I am using JSF 2.2 with Primefaces 4 on a Tomcat 7.
I have a form in which certains fields are required depending on the value of a checkbox. So In the example below, the fields in the fieldset are required only if the checkbox is checked (which is, by default) :
<h:form id="formId">
...
<p:selectBooleanCheckbox id="fieldId1" value="#{myBean.firm}">
<p:ajax event="change" process="@this :formId:fieldsetId" update="@this :formId:fieldsetId"/>
</p:selectBooleanCheckbox>
...
<p:fieldset id="fieldsetId">
<p:inputText id="field2" value="#{myBean.field2Value}" required="#{myBean.firm}"/>
<p:inputText id="field3" value="#{myBean.field3Value}" required="#{myBean.firm}"/>
</p:fieldset>
</h:form>
My problem is that the ajax request passes through the validation, so when i unchecked the checkbox, the validation fails on the inputFields if they are not filled, and the model is not updated.
So my attribute firm is still set to true in myBean and my inputText fields are still required.
At first I forgot to process the fieldset
<p:ajax event="change" process="@this" update="@this :formId:fieldsetId"/>
This worked, or I though, but as the field are not processed, if I filled some fields before unchecking the box, all the data were lost. Setting immediate="true" won't work either in that case.
It seems to me to be a very simple and common usecase, and I can't believe there is not a solution.
Thanks