[英]JSF 2 Mojarra — Required attribute not being honored after f:ajax render
Consider this simple example.考虑这个简单的例子。 If I have a form like this I obviously get a validation error when submitting with no value in the inputText:
如果我有这样的表单,那么在 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>
But when I re-render the panelGroup w/ f:ajax the required attribute is not being honored and I can submit with an empty value:但是当我重新渲染带有 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>
I'm testing in mojarra 2.1.1.我正在 mojarra 2.1.1 中进行测试。 Any advice is appreciated.
任何建议表示赞赏。
update: I figured it out.更新:我想通了。 BackButtonTestBean was in request scope so the value of testSelectOneMenu was not 'mouse' when I submitted the form.
BackButtonTestBean 在请求 scope 中,所以当我提交表单时 testSelectOneMenu 的值不是“鼠标”。 Consequently it wasn't rendered and thus the validators were invalid.
因此它没有被渲染,因此验证器是无效的。 Changed to @ViewScoped and works as expected.
更改为 @ViewScoped 并按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.