202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
A more direct way of creating an Outlook mail item from the Notes client
Wed, Nov 1st 2017 8
Sending an automated mail using Outlook from a Notes agent
Tue, Sep 12th 2017 7
Breweries and tap rooms for #MWLUG
Sat, Jul 29th 2017 4
So where can I go for dinner near #MWLUG?
Thu, Jul 27th 2017 3
Creating a meeting notice in Outlook from the Notes client
Fri, Jun 23rd 2017 7
Getting email addresses from the Notes address book
Wed, Jun 21st 2017 6
Progammatically opening a mailto link from the Notes client
Fri, Jun 2nd 2017 6
Top 10
Exporting from #XPages to Excel without Excel, Part 2
Thu, Sep 26th 2013 13
Dirty pages and keeping users on them in #XPages
Wed, Apr 16th 2014 12
Simple dialog returning a value to your #XPages
Wed, Jul 16th 2014 12
Exporting from #XPages to Excel without Excel, Part 1
Wed, Sep 25th 2013 11
Java still not refreshing correctly in #XPages 8.5.3 UP 1
Mon, Nov 4th 2013 9
Showing a database in a panel in #IBMNotes
Tue, Jul 22nd 2014 9
Configurable notification agent in #OldNotes
Thu, Sep 25th 2014 9
Sessions for #MWLUG2016
Fri, Jul 1st 2016 9
Copying design elements via script in #XPages
Wed, Jan 29th 2014 8
A more direct way of creating an Outlook mail item from the Notes client
Wed, Nov 1st 2017 8


Dirty pages and keeping users on them in #XPages
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
David Navarre    

As I’ve mentioned before, sometimes XPages does not react the way your Notes users would expect it to react. In particular, I’ve had issues with ensuring that XPages warns the user when they try navigating away from a page that they’ve edited without first saving it. Such pages are “dirty”, since something has changed on them. Back in November we examined this in my post on Modified flags in XPages.

Unfortunately, sometimes I want to inform the user that they’re leaving a dirty page and other times I don’t. Also, sometimes, I seem to be able to add things that don’t warn the user that they’re leaving a dirty page. I’m sure there is consistency, but I haven’t figured out the rules, so I have added some code that handles these situations.

Simple warning of a dirty page

This was described in that prior post. Set the enableModifiedFlag to true and provide a couple of properties to handle it. This should fire whenever you close the XPage or navigate away via a standard link.

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" enableModifiedFlag="true">
	<xp:this.modifiedControl>
		<![CDATA[#{javascript:if ( true ) {return "saveButton1"}}]]>
	</xp:this.modifiedControl>
	<xp:this.modifiedMessage>
		<![CDATA[#{javascript:"Purchase order modified. Click OK to save, cancel to continue without saving"}]]>
	</xp:this.modifiedMessage>
...
</xp:view>

Unfortunately, I’ve found that sometimes, it doesn’t warn me.

Warning when clicking links

I’ve got some navigation on the left side of my XPages, set up in a lovely dojo accordian with links to different parts of the application. However, not every link is set up in the same way. Some are simple and use the modifiedControl to warn users, like this one:

<xp:link text="Attachments" escape="true" id="link3" value="/att_attachmentManagement_view.xsp">
</xp:link>

Some, however, run some scripts to remove some sessionscope variables when switching pages and I was having challenges getting the server-side Javascript to execute. So, I found a way to do both:

<xp:link text="Payment requests" escape="true" id="paymentLink" target="_self" value="#">
	<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
		<xp:this.action><![CDATA[#{javascript:clearDynamicViewSettings();
context.redirectToPage("/pro_paymentRequest_view.xsp");}]]></xp:this.action>
	</xp:eventHandler>
</xp:link>

The unfortunate thing is that when I’m using the redirect, it ignores the dirtiness of the page. Fortunately, Per Henrik Lausten found a way to deal with it on StackOverflow (thanks to PSolano), and posted it as an XSnippet on OpenNTF.

if (XSP._isDirty()){
  if (confirm ("Are you sure you want to navigate away from this page?" + "n" + "n" +
    "This document may contain unsaved changes." + "n" + "n" +
    "Press OK to continue, or Cancel to stay on the current page.")) {
    return true;
  } else {
    return false;
  }
} else {
  return true;
}

So, when I added that explicitly as client-side Javascript to each eventhandler, it worked beautifully. Now, being a fan of reusable code, I wanted to put it in a CSJS script library and invoke the function all over the place. My function was as shown above, with a little wrapper:

function isClean() {
	if (XSP._isDirty()){
	    ....
	}
}

Then, I just needed to invoke it. My first attempt looked great to me. Call isClean() and the client side would warn the user, then stop them as appropriate.

<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
	<xp:this.action><![CDATA[#{javascript:clearDynamicViewSettings();
context.redirectToPage("/pro_paymentRequest_view.xsp");}]]></xp:this.action>
	<xp:this.script><![CDATA[isClean();]]></xp:this.script>
</xp:eventHandler>

Ummmm, but that didn’t work. In order to prevent the server-side Javascript from executing, the client-side Javascript needs to RETURN false, not just compute it.

<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
 <xp:this.action><![CDATA[#{javascript:clearDynamicViewSettings();
 context.redirectToPage("/pro_paymentRequest_view.xsp");}]]></xp:this.action>
 <xp:this.script><![CDATA[return isClean();]]></xp:this.script>
</xp:eventHandler>

That’s added bonus knowledge – not only are we learning how to stick to dirty pages, we’ve also learned that if you have the CSJS return a value of false, it will not execute the SSJS. I’m sure you can grasp the opportunities for validation provided there.

What about when you don’t want to warn them?

In our application, the user can select the action to perform from a combobox and then click a button to execute it. (Thanks to Scott Good, Henry Newberry and the folks at Teamwork Solutions!) The challenge here is that when the user changes the value in the combobox, the page is dirty! I mean, no data may have changed other than that combobox, but the XPage still feels dirty. Since some of those actions will result in saving the document and all of them result in navigation away from this page in an expected and managed way, we don’t want it to feel dirty. To dodge the problem, I just add a little CSJS to convince that page that it’s not really dirty.

<xp:this.script><![CDATA[XSP._setDirty(false,"");]]></xp:this.script>

So, then the modifiedControl is not tipped off and we execute the intended commands. Now, I’m pretty sure we don’t run into this problem with standard save buttons, but we’re in an unusual case of taking two steps to execute one action.

Note

YMMV. These private calls to XSP methods may go away and using them requires care to ensure you’ve got the right parameters, or so the XPages Portable Command Guide advises us. Of course, everything we code may call functions that will go away and we always need to get the parameters right. So, I’m gonna use them, though sparingly.




---------------------
http://lostinxpages.com/2014/04/16/dirty-pages-and-keeping-users-on-them-in-xpages/
Apr 16, 2014
13 hits



Recent Blog Posts
8
A more direct way of creating an Outlook mail item from the Notes client
Wed, Nov 1st 2017 3:54p   David Navarre
A
7
Sending an automated mail using Outlook from a Notes agent
Tue, Sep 12th 2017 11:14p   David Navarre
A
4
Breweries and tap rooms for #MWLUG
Sat, Jul 29th 2017 4:49p   David Navarre
A
3
So where can I go for dinner near #MWLUG?
Thu, Jul 27th 2017 10:02p   David Navarre
A
7
Creating a meeting notice in Outlook from the Notes client
Fri, Jun 23rd 2017 5:23p   David Navarre
A
6
Getting email addresses from the Notes address book
Wed, Jun 21st 2017 5:50p   David Navarre
A
6
Progammatically opening a mailto link from the Notes client
Fri, Jun 2nd 2017 9:35p   David Navarre
A
5
What good is the internet of things to people who don’t have internet?
Tue, Feb 21st 2017 8:36p   David Navarre
A




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition