考虑这个简单的例子。如果我有这样的表单,那么在inputText中提交没有值时,我显然会收到验证错误:
<h:form id="testForm" prependId="false">
<h:selectOneMenu
id="testSelectOneMenu"
value="#{backButtonTestBean.selection}">
<f:selectItem itemValue="mickey" itemLabel="Mickey" />
<f:selectItem itemValue="mouse" itemLabel="Mouse" />
<f:ajax execute="@this" render="panel" />
</h:selectOneMenu>
<h:panelGroup layout="block" id="panel">
<h:panelGroup layout="block">
<h:inputText id="requiredField" required="true" />
</h:panelGroup>
</h:panelGroup>
<h:commandButton value="submit" action="#{backButtonTestBean.submit}" />
</h:form>
但是当我重新渲染panelGroup w / f:ajax时,所需的属性没有被尊重,我可以提交一个空值:
<h:form id="testForm" prependId="false">
<h:selectOneMenu
id="testSelectOneMenu"
value="#{backButtonTestBean.selection}">
<f:selectItem itemValue="mickey" itemLabel="Mickey" />
<f:selectItem itemValue="mouse" itemLabel="Mouse" />
<f:ajax execute="@this" render="panel" />
</h:selectOneMenu>
<h:panelGroup layout="block" id="panel">
<h:panelGroup layout="block" rendered="#{backButtonTestBean.selection == 'mouse'}">
<h:inputText id="requiredField" required="true" />
</h:panelGroup>
</h:panelGroup>
<h:commandButton value="submit" action="#{backButtonTestBean.submit}" />
</h:form>
我正在测试mojarra 2.1.1。任何建议都表示赞赏。
答案 0 :(得分:0)
更新:我想通了。 BackButtonTestBean在请求范围内,因此当我提交表单时,testSelectOneMenu的值不是“鼠标”。因此它没有呈现,因此验证器无效。更改为@ViewScoped并按预期工作。