JSF 2 Mojarra - f:ajax 渲染后未遵循必需的属性

发布于 2024-11-04 21:16:04 字数 1760 浏览 0 评论 0原文

考虑这个简单的例子。如果我有这样的表单,那么在 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 中进行测试。任何建议表示赞赏。

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:

<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:

<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. Any advice is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莳間冲淡了誓言ζ 2024-11-11 21:16:04

更新:我想通了。 BackButtonTestBean 在请求范围内,因此当我提交表单时 testSelectOneMenu 的值不是“鼠标”。因此它没有被渲染,因此验证器是无效的。更改为 @ViewScoped 并按预期工作。

update: I figured it out. BackButtonTestBean was in request scope so the value of testSelectOneMenu was not 'mouse' when I submitted the form. Consequently it wasn't rendered and thus the validators were invalid. Changed to @ViewScoped and works as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文