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
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.