Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with valueChangeListener and h:selectbooleancheckbox

 
john cartman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic