---- Philipp Daumke <[EMAIL PROTECTED]> schrieb:
> Hi all,
> 
> I'm absolutely new to JSF and find it very hard to get a good 
> documentation for specific problems. Maybe you can help me with this 
> little problem. I want to use a checkbox and a inputText. When I 
> activate the checkbox, the inputText shall be enabled so that i can 
> write something in it. If I uncheck the checkbox the inputFile shall be 
> grey again. So far, I only have
> 
> <h:selectBooleanCheckbox id="checkbox1" value="#{user.toggleFileUsage}"/>
> <h:inputText id="inputFile" disabled="#{user.fileUsed}" value="Type your 
> text here" />
> 
> and the bean user:
> public class User {
>     private boolean fileUsed = false;
> 
>     public void toggleFileUsage() {
>         fileUsed = !fileUsed;
>         }
>     public boolean isFileUsed() {
>         return fileUsed;
>     }
>     public void setFileUsed(boolean fileUsed) {
>         this.fileUsed = fileUsed;
>     }
> }
> 
> However, this doesn't work. I also tried a little with bindings and 
> Listeners, but didn't really know how to use them. As I said, I don't 
> find any good documentation or tutorial for this.

The best thing to do would be to buy a book on JSF. There are a number of good 
ones now. Online help is useful for specific problems, but this is more of a 
general JSF concept.

A boolean checkbox is either true or false, and will set a property on your 
backing bean to either true or false when the page is submitted. In other 
words, it *always* calls the appropriate setter method on each submit, passing 
true or false. It does not support "toggle" type functionality, where a method 
is called only on a change of checkbox state.

So you just need to get rid of all that "toggle" stuff, and map the checkbox to 
control the "fileUsed" property on your backing bean directly. The checkbox 
will set it, and the inputText will use the current setting to determine 
whether it is disabled or not. No toggling stuff required.

Regards,
Simon

Reply via email to