The problem you are having is the nature of JSF and postbacks.
In your example. lets say it is initially disabled.
1. user clicks checkbox
2. you submit the form
3. decode the checkbox and inputtext (which is disabled)
4. validate checkbox (no validation on the disabled inputText)
5. update the checkbox value
6. re-render the page
This process should work for you if you aren't worried by validation errors.
If you are worried about validation errors, make the code that submits the
form immediate.
If you are using trinidad, try this:
<tr:document>
<tr:form>
<tr:selectBooleanChechbox
id="myCheckbox"
label="Select me to enter text"
value="#{bean.test}"
autoSubmit="true" />
<tr:inputText
disabled="#{not bean.test}"
value="#{bean.test2}"
partialTriggers="myCheckbox" />
</tr:form>
</tr:document>
Note that if the inputText is disabled, it will not update so the test2 in
this case will remain in its current value. So if you want it to be null
when disabled you would need to have it be set to null in the bean's
setTest(boolean) method, or add a listener to the checkbox to do it.
Now if you start having validation problems, you need a way to only
update/validate the checkbox. In this case I would recommend that you use
the tomahawk subForm component and wrap it around the checkbox.
-Andrew
On Jan 14, 2008 1:13 PM, Philipp Daumke <[EMAIL PROTECTED]> wrote:
> 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.
> All the best
> Philipp
>
>
>
>
>
>