Use <f:ajax event="click" render="@form">
in the checkbox and give the component containing the form elements a rendered
attribute which depends on the checkbox's state. No need for another JS code clutter.
<h:form>
<fieldset>
<legend>
<h:selectBooleanCheckbox binding="#{showUserInfo}">
<f:ajax event="click" render="@form" />
</h:selectBooleanCheckbox>
<h:outputText value="User information" />
</legend>
<h:panelGroup rendered="#{not empty showUserInfo.value and showUserInfo.value}">
<p>
<h:outputLabel for="firstName" value="First name:" />
<h:inputText id="firstName" value="#{bean.user.firstName}" />
</p>
</h:panelGroup>
</fieldset>
</h:form>
The above example binds the checkbox to the view, you can of course also bind it to a boolean
bean property, you can then remove the not empty
check from the rendered
attribute.
<h:selectBooleanCheckbox value="#{bean.showUserInfo}">
...
<h:panelGroup rendered="#{bean.showUserInfo}">