Franck Quinard wrote:
> Hello,
>
> I have a problem with the behavior of the commandButton. I want it to
> disable the comboBox when I click ones on it and I want it to enable
> the comboBox when click on it again. The first part is working but the
> second doesn't.
>
> Here is the code
>
> <h:selectOneMenu value="#{resumeBean.bgColor}"
> disabled="#{!resumeBean.colorSupported}">
> <f:selectItems value="#{resumeBean.availableColors}"/>
> </h:selectOneMenu>
>
> <h:commandButton value="#{resumeBean.colorSupportLabel}"
>
> actionListener="#{resumeBean.toggleColorSupport}"
> immediate="true"/>
>
>
> in the bean.
>
> public void toggleColorSupport(ActionEvent event) {
> isColorSupported = !isColorSupported;
> }
>
>
> public boolean isColorSupported() {
> return (isColorSupported);
> }
>
> any idea why the second click on the button doesn't get trigger the
> listener of the selectOneMenu?Thank you
>
> Franck
Franck,
I've tried a similar test locally and don't see a problem.
Here is what I have:
----------------------------------------- CommandButtonTest.jsp
------------------------------------
<f:view>
<h:form>
<h:selectOneMenu value="#{test.color}"
disabled="#{test.colorSupported}">
<f:selectItem itemValue="red" itemLabel="red"/>
<f:selectItem itemValue="green" itemLabel="green"/>
<f:selectItem itemValue="blue" itemLabel="blue"/>
</h:selectOneMenu>
<h:commandButton value="Click Me"
actionListener="#{test.toggle}"
immediate="true"/>
</h:form>
</f:view>
--------------------------------------------------------------------------------------------------------------
------------------------------------------------ test bean
-------------------------------------------------
public void toggle(ActionEvent actionEvent) throws AbortProcessingException{
disabled = !disabled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isColorSupported() {
return disabled;
}
--------------------------------------------------------------------------------------------------------------