This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Help with valueChangeListener and h:selectbooleancheckbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Help with valueChangeListener and h:selectbooleancheckbox" Watch "Help with valueChangeListener and h:selectbooleancheckbox" New topic
Author

Help with valueChangeListener and h:selectbooleancheckbox

john cartman
Greenhorn

Joined: Jun 29, 2011
Posts: 6
Hi Geniuses, I need your help!

So here is my dilemma, I'm trying to enable/disable a button depending on whether at least one check-box is checked or not in a table. I'm trying to use a valueChangeListener (my first time using this) but I can't seem to get it to work.

Here is my code for the table and button.




This is my bean code.



Can someone please help me out?

Thanks in advance!

PS: I know that document.getElementByID("selectMessage").checked) is not the correct syntax, but I dont know the right way to do it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

Couple of problems here. Don't capitalize object instance or property names (EnableDisable.Checkbox). The convention is to capitalize class names and lowercase the inital letter of instances, methods, and properties, and it's bad practice at best, and a potential fight with JSF at worst if you don't adhere to the convention.

ValueChangeListener is fired as a part of the form submit process, so if you're hoping to dynamically update the page, you're out of luck. You'd need to add AJAX support to your checkboxes for that.

Even with AJAX, however, the entire form will be submitted by default, which means that the valueChangeListener will only fire if ALL controls in the form have valid values, so your best bet is to constrain the submit to just the checkbox itself.

Normally you get the value of a control by querying the control's property (that is "isCheck1()" for checkbox 1, since it's a boolean property). However, the valueChangeListener is part of the updating process, so that's not something to rely on. ValueChangeListeners really should ONLY pay attention to the value being changed. For something that needs to know about the form as a whole, use an action processor instead.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Don't get me started about those stupid light bulbs.
 
subject: Help with valueChangeListener and h:selectbooleancheckbox
 
Similar Threads
Problem Selecting DataTable Row
JSF DATA TABLE NAVIGATION PROBLEM
datatable - row colors
Help with ADF Table, Checkboxes and Buttons
Button doesnt get enabled