Ajax render not working on SelectBooleanCheckbox

后端 未结 1 614
闹比i
闹比i 2020-12-22 02:07

I have a JSF form and on which I have a selectBooleanCheckbox. If the value of the checkbox is true I want to display the combo box next to it. But somehow it is not working

相关标签:
1条回答
  • 2020-12-22 02:41

    The straightforward way to achieve the functionality you desire is, literally, to rerender the combobox basing on the selection of the checkbox. That is done in a following way:

    <h:selectBooleanCheckbox binding="#{checkbox}">
        <f:ajax render="group" />
    </h:selectBooleanCheckbox>
    <h:panelGroup id="group">
        <h:selectOneMenu ... rendered="#{checkbox.value}" />
    </h:panelGroup>
    

    Note that the code doesn't need any special fields in the bean and the UIComponent is bound to the view.

    Of course, you can do it via a bean property as well, if you need it in your model:

    <h:selectBooleanCheckbox value="#{bean.value}">
        <f:ajax render="group" />
    </h:selectBooleanCheckbox>
    <h:panelGroup id="group">
        <h:selectOneMenu ... rendered="#{bean.value}" />
    </h:panelGroup>
    

    Also worth noting is that this functionality can be achieved by plain JavaScript as well, by toggling the display attribute of an element between none and block. But be aware that you must keep the status of JSF components consistent across postbacks to secure against possible malicious attack threats.

    0 讨论(0)
提交回复
热议问题