问题
help me please! I am novice. I have 3 components of . If the first selectBooleanCheckbox checked then the second and third components should be disabled. And if the first selectBooleanCheckbox unchecked then the second and third components should be active.
<h:selectBooleanCheckbox id="checkBox_1" value="#{MyManagerBean.goldRun}"
valueChangeListener="#{MyManagerBean.valueChangeInput}"/>
<h:selectBooleanCheckbox id="checkBox_2" value="#{MymanagerBean.useResult}" />
<h:selectBooleanCheckbox id="checkBox_3" value="#{MymanagerBean.goldSize}" />
How do i do it?
public void valueChangeInput(ValueChangeEvent event) {
event.getNewValue()......
.............................
..............................
}
回答1:
I think the kind of behaviour you are looking for can only be accomplished using ajax. If you are using JSF2 then ajax is built into it. You could do something like:
<h:selectBooleanCheckbox id="checkBox_1" value="#{MyManagerBean.goldRun}">
<f:ajax event="change" render="checkBox_2 checkBox_3"/>
</h:selectBooleanCheckbox>
<h:selectBooleanCheckbox id="checkBox_2" value="#{MymanagerBean.useResult}" disabled="#{MyManagerBean.goldRun}" />
<h:selectBooleanCheckbox id="checkBox_3" value="#{MymanagerBean.goldSize}" disabled="#{MyManagerBean.goldRun}"/>
The above piece of code would have to be in a form.
If your using JSF 1.2 then you will need to use an ajax supported JSF third party library like RichFaces / ICEfaces. They have similar components that work in the same way.
来源:https://stackoverflow.com/questions/7413973/how-to-make-checkboxes-disabled-when-other-checkbox-is-checked