考虑这个简单的例子。如果我有这样的表单,那么在 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>
但是当我重新渲染带有 f:ajax 的 panelGroup 时,所需的属性没有被兑现,我可以使用空值提交:
<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 中进行测试。任何建议表示赞赏。