Modified flags in #XPages

One of the initially most frustrating things about XPages was that, unlike in standard Notes, if the user closed a window without saving, it never warned them. If you expect to be warned and never are, you’re bound to lose some data and be frustrated.

Fortunately, you can design your application to pay attention to whether the user has “dirtied” the page by editing it, even identifying down to specific input elements of which you care or don’t care about the “dirtyness”. I can’t explain why they wouldn’t have made it the default behavior, since it is the default behavior in Notes, but they did.

In the original edition of Mastering XPages, I got out to around page 300 before specific work inhibited me from further page-by-page progress, so I never got to read Chapter 13, on XPages in the Notes Client (XPiNC). I’m very surprised, since most of my work now needs to run XPiNC.

So, the key to making your custom controls and XPages being “cleanliness-aware” is to set the enableModifiedFlag = “true“. This allows the system to keep track of whether something within that element has been dirtied by the user and, if so, complain when the user tries to navigate away. You can even create a custom message for the user and specify a control to execute if the user clicks OK.

<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>

Now, the unfortunate thing is that the only containers that this flag works on are the big ones – the XPage or the custom control. I’d really like to be able to use it on a panel or table or some smaller element, so I can package my concern for ‘cleanliness’ in slightly more granular ways.

Fortunately, they also allow you to use the disableModifiedFlag on specific core controls. It is really important to note that the enableModifiedFlag takes precedence, so you cannot use disableModifiedFlag=”false” to get your notice if you didn’t enable it on the custom control or XPage.

The following Core Controls support this feature:

  • Edit Box
  • Multiline Edit Box
  • List Box
  • Combo Box
  • Check Box
  • Radio Button
  • File Upload
  • Date Time Picker
  • Rich Text Editor

Again, this is a property I’d like to see on other containers so that I can use fewer properties to granularize my cleanliness monitoring (and maybe save minor bits of memory and bandwidth?).

Caveat

Not everything that you would consider “navigating away from the page” gets treated by XPages. I’m not sure of everything that it ignores, but I do know that when we had navigation using the simple action openPage, the system never warned me that I was navigating away from the page – browser or XPiNC. Fortunately, I was able to discard the simple actions that were running in that link and just have it use the URL for the XPage I wanted to navigate to, allowing notification of dirtyness,

This method did not work:

<xp:link text="All inventory" escape="true" id="link30">
	<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
		<xp:this.action>
			<xp:actionGroup>
				<xp:executeScript script="#{javascript:clearDynamicViewSettings()}">
				</xp:executeScript>
				<xp:openPage target="openDocument" name="/inv_allInventory_view.xsp">
				</xp:openPage>
			</xp:actionGroup>
		</xp:this.action>
	</xp:eventHandler>
</xp:link>

After I figured out I didn’t actually need to run that bit of javascript, it made it easy to switch to this link, which did prompt when the page was dirty:

<xp:link text="All inventory" escape="true" id="inventoryLink" target="_self"
value="/inv_allInventory_view.xsp">
</xp:link>

While I’m sure there are ways around the openPage failure and some way of doing all via javascript, I’m happy with this first step to making XPiNC react the way my Notes users expect it to react.

Advertisements
Categories: Xpages | Tags: , , | 1 Comment

Post navigation

One thought on “Modified flags in #XPages

  1. Pingback: Dirty pages and keeping users on them in #XPages | Lost in XPages, Soon to be Found

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: