<h:form id="formEdit">
<p:selectOneMenu value="#{testView.selection}"
required="true">
<f:selectItem itemValue="noMenu" itemLabel="selectOneMenu not rendered"/>
<f:selectItem itemValue="haveMenu" itemLabel="selectOneMenu rendered"/>
<p:ajax update="formEdit"/>
</p:selectOneMenu>
<p:panel>
<p:selectOneMenu id="conditionallyRnedered" value="#{testView.value}"
rendered="#{testView.selection eq 'haveMenu'}"
required="true">
<f:selectItem itemValue="#{null}" itemLabel="-" noSelectionOption="true"/>
</p:selectOneMenu>
</p:panel>
<p:messages id="messages"/>
<p:commandButton value="Submit"/>
</h:form>
Component "conditionallyRnedered"
is required, and rendered on page after i select "haveMenu"
value in first menu. This component have only empty option and initialy its not rendered on page. If i press Submit button, then response is:
<partial-response><changes>
<update id="javax.faces.ViewState"><![CDATA[stateless]]></update>
</changes></partial-response>
There is no validation error. If i change value of rendered
attribute in "conditionallyRnedered"
from "#{testView.selection eq 'haveMenu'}"
to just "true"
, then response is:
<partial-response><changes>
<update id="javax.faces.ViewState"><![CDATA[stateless]]></update>
<extension ln="primefaces" type="args">{"validationFailed":true}</extension></changes>
</partial-response>
Validation error returned. The questions is:
- Why conditionally rendered component is not validated?
- It is possible to make them validated?
UPD
Originally in my question is absent Bean source code, in which Bean declared as @ViewScoped
. After read @BalusC comment, i try to change scope from @ViewScoped
to @SessionScoped
, and after that validation is working correctly. Wherein javax.faces.ViewState
in response changed from stateless
to some view id:
<update id="javax.faces.ViewState">-5902669082498843838:729675320168079573</update>
I still doubt, this is solution or still workaround, because I thought that instance of @ViewScoped
bean is exist while we dont left the page. Maybe this behavior is caused by the fact that in the same page present another bean, with @SessionScoped
scope.