202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 9
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 8
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 9
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 10
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 8
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 7
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 6
Top 10
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 10
Displaying fancy loading indicator while loading AJAX
Fri, Nov 11th 2011 9
OpenLog Implementation in XPages
Sun, Jul 31st 2011 9
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 9
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 9
Cross-wise MouseOver Highlight of table row, column and cell
Sun, Jul 31st 2011 8
XPages Reserved Names for design elements
Sun, Jul 31st 2011 8
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 8
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 8
XPages: Handling disabled Checkboxes
Thu, Mar 26th 2015 7


XPages: Handling disabled Checkboxes
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Frederic dehedin    

In a recent XPages workflow application i bumped into a nasty behaviour of the xp:checkBox control:
In a certain step of a workflow document, a checkbox is displayed as disabled, but still showing the checkbox state (checked or unchecked) which was set in a previous workflow step. When the user then submitted the data, this value will be cleared(!).

Let’s check this out with an example:

The following page shows a simple page with a checkbox and a submit button.. an xp:text control shows the checked/unchecked value of the checkbox.

xpages_checkbox

And the according code:

<xp:checkBox text="I am a normal checkbox switch me on or off..."
 id="checkBox2" checkedValue="i am on" value="#{sessionScope.checkboxValue}"
 uncheckedValue="i am off" disabled="#{sessionScope.checkboxDisabled=='1'}"></xp:checkBox>
 <br />
 <br />
 <xp:button value="Submit" id="button1">
 <xp:eventHandler event="onclick" submit="true"
 refreshMode="complete" disableValidators="true">
 </xp:eventHandler>
 </xp:button>
 <br />
 <br />
 <xp:text escape="true" id="computedField2"
 value="And the value of the checkbox is: #{sessionScope.checkboxValue}"></xp:text>

So far so good. Now lets assume User A checked the checkbox and saved the data record. User B will open the document (edit-mode), but due to some business logic does only see this checkbox as disabled (and checked):

xpages_checkbox_disabled

 

If User B wants to submit his entered data and clicks “submit”, the value of the checkbox is also submitted, but resets the value!

xpages_checkbox 4

So what happened? Altough the checkbox was disabled, User B submitted the “unchecked” value of the checkbox to the server.

So how to avoid this? The magic property is readonly.. You have to set this to “true”, if you don’t want the user to change the value of this field anymore.. So either you compute the readonly property to true / false with the same logic of the disabled property, or you can also use a generic computation like this: readonly=”#{javascript:this.isDisabled()}”.

Check out the complete code as an example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

 <div style="margin:50px;">
 <xp:checkBox text="Set the checkbox below to disabled or enabled.."
 style="font-style:italic" id="checkBox1" checkedValue="1"
 uncheckedValue="0" value="#{sessionScope.checkboxDisabled}">
 <xp:eventHandler event="onclick" submit="true"
 refreshMode="complete" disableValidators="true">
 </xp:eventHandler>
 </xp:checkBox>
 <br />
 <br />
 <xp:checkBox text="I am a normal checkbox switch me on or off..."
 readonly="#{javascript:this.isDisabled()}" id="checkBox2"
 checkedValue="i am on" value="#{sessionScope.checkboxValue}"
 uncheckedValue="i am off" disabled="#{sessionScope.checkboxDisabled=='1'}"></xp:checkBox>
 <br />
 <br />
 <xp:button value="Submit" id="button1">
 <xp:eventHandler event="onclick" submit="true"
 refreshMode="complete" disableValidators="true">
 </xp:eventHandler>
 </xp:button>
 <br />
 <br />
 <xp:text escape="true" id="computedField2"
 value="And the value of the checkbox is: #{sessionScope.checkboxValue}"></xp:text>
 </div>
</xp:view>


---------------------
http://www.fdehedin.ch/476/xpages-handling-disabled-checkboxes-and-radiobuttons
Mar 26, 2015
8 hits



Recent Blog Posts




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