File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Help with valueChangeListener and h:selectbooleancheckbox" Watch "Help with valueChangeListener and h:selectbooleancheckbox" New topic

Help with valueChangeListener and h:selectbooleancheckbox

john cartman

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

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Help with valueChangeListener and h:selectbooleancheckbox
It's not a secret anymore!