199 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 5
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 4
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 10
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 6
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 11
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 8
Top 10
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 11
Creating a test environment: the easy way
Tue, Jun 3rd 2014 10
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 10
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 8
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 7
XPages Reserved Names for design elements
Sun, Jul 31st 2011 6
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 6
My top 5 wishlist for IBM Notes / IBM Domino Designer, which ones are yours?
Wed, Aug 6th 2014 5
Get rid of the agent property “Target documents – all new & modified documents”
Tue, Jan 3rd 2012 5
XPages: Handling disabled Checkboxes
Thu, Mar 26th 2015 5


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



Recent Blog Posts
5
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 4:17p   Frederic Dehedin
Recently i studied for the Java SE 8 Programmer I Exam (Java OCA for short) and was glad that i passed it on the first go. Although i’ve been practicing programming in Java several years, i decided to sustain my practical knowledge with some theoretical background and i’m happy to share my experience in this blog […]
4
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 12:23p   Frederic Dehedin
Just yesterday we came back to Switzerland after our 3 Weeks holidays in Indonesia. We were in Bali, Nusa Lembongan (Island next to Bali) and Rote Island (Timor). So on the 16. September 2016, after a beautiful day on the boat diving with Manta Rays, i was eager to check the contest results and received […]




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