【问题标题】:How to re-render <p:panel> from <p:selectOneRadio> option when form fails a validation?当表单验证失败时,如何从 <p:selectOneRadio> 选项重新渲染 <p:panel>?
【发布时间】:2014-07-25 12:05:46
【问题描述】:

在页面初始加载期间渲染工作正常,但是一旦提交表单并且某些组件失败,验证重新渲染不会触发,面板不再显示和隐藏,必须再次刷新页面。我还是 jsf 的新手。

示例代码

    <p:selectOneRadio id="accommodationOptions" value="#{travelRequestMBean.accommodationOptions}">  
                        <f:selectItem itemLabel="#{field['accord3Radio2']}" itemValue="2" />  
                        <f:selectItem itemLabel="#{field['accord3Radio1']}" itemValue="1" />
                        <f:ajax render="panelMoreAccommodation2"/> 
    </p:selectOneRadio>

    <p:panel id="panelMoreAccommodation2" widgetVar="panelMoreAccommodation2" 
            visible="#{travelRequestMBean.accommodationOptions == 1}" closable="true" toggleable="true">
                    <p:graphicImage url="/images/hotel-noun_project_4398.svg" alt="#{field['accord3Label2']}" height="24px" />
                    <h:outputText value="#{field['accord3Label2']}" />
    </p:panel>

我还尝试了另一种变体,使用支持 bean 中的布尔属性和 selectoneradio 上的 ajax 事件,结果仍然相同,面板不执行任何操作。

【问题讨论】:

    标签: ajax jsf primefaces


    【解决方案1】:

    我看不到您在哪里验证您的输入。不过看看http://www.primefaces.org/showcase/ui/csv/basic.xhtml

    的组合
    update=":panelMoreAccommodation2"
    

    而不是可见的使用渲染。

    【讨论】:

    • 我没有包含验证,它只是一个带有 required="true" 的简单字段,而且更新是我在 &lt;p:ajax event="click" listener="#{travelRequestMBean.accommodationFlag()}" update=":#{p:component('panelMoreAccommodation2')}"&gt; &lt;/p:ajax&gt; 中使用它的第一个方法跨度>
    • 这不起作用?随着“更新”?我认为您必须向您添加一个事件 f:ajax event="..." 但我不知道是哪一个。或者尝试用 ajax .. 包围 selectOneRadio 元素并尝试 p:ajax primefaces.org/showcase/ui/ajax/listener.xhtml
    • 这正常工作。我的问题是提交表单但验证失败后,它将停止工作。
    • 好吧,我必须学会阅读...... :D 我不清楚,你有没有尝试过这样的事情
    【解决方案2】:

    终于做了一些调整,问题是目标面板上的这个属性

    closable="true"
    

    删除此属性后,即使在提交验证失败后,ajax 更新也会再次起作用。

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 2020-02-23
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多