How to make checkboxes disabled when other checkbox is checked?

给你一囗甜甜゛ 提交于 2019-12-13 06:50:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!