【问题标题】:Keep p:dialog open when validation failed验证失败时保持 p:dialog 打开
【发布时间】:2019-09-25 09:36:44
【问题描述】:

我有一个带有数据表的简单页面。在表格上方有一个按钮来添加一个新的表格行。此按钮会打开一个带有注册表单的弹出式表单。以该表单创建的对象具有 bean 验证集。现在,当我提交无效表单时,不会添加数据,会创建一条消息并关闭弹出窗口。

我的问题是我想保持弹出窗口打开,以防验证未通过。

弹窗代码:


<p:dialog header="New company registration" widgetVar="cmpRegDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
                            <p:outputPanel id="cmpRegistration" style="text-align:center;">
                                <h:panelGrid id="cmpRegistrationGrid" columns="3" columnClasses="label,value" cellpadding="5">

                                    <p:outputLabel for="cmpNameR" value="Name:"/>
                                    <p:inputText id="cmpNameR" value="#{companyBean.newCompany.name}" />
                                    <p:message for="cmpNameR" />

                                    <p:outputLabel for="cmpAddressR" value="Address:"/>
                                    <p:inputText id="cmpAddressR" value="#{companyBean.newCompany.address}" />
                                    <p:message for="cmpAddressR" />

                                    <p:outputLabel for="cmpIcoR" value="ICO:"/>
                                    <p:inputText id="cmpIcoR" value="#{companyBean.newCompany.ico}" />
                                    <p:message for="cmpIcoR" />

                                    <p:commandButton value="Submit" styleClass="secondary-btn flat" action="#{companyBean.registerNewCompany()}" update=":companyRegistrationForm :companiesOverviewForm"/>
                                    <p:commandButton value="Reset" update="cmpRegistrationGrid" process="@this" style="margin-right:10px; width: auto;" styleClass="indigo-btn" >
                                        <p:resetInput target="cmpRegistrationGrid" />
                                    </p:commandButton>
                                </h:panelGrid>
                            </p:outputPanel>
                        </p:dialog>

【问题讨论】:

标签: jsf primefaces dialog


【解决方案1】:

是的,只需将其添加到您的“提交”按钮oncomplete="if (!args.validationFailed) PF('#cmpRegDialog').hide();"

<p:commandButton value="Submit" 
                 styleClass="secondary-btn flat" 
                 action="#{companyBean.registerNewCompany()}" 
                 update=":cmpRegistration :companiesOverviewForm"/>
                 oncomplete="if (!args.validationFailed) PF('#cmpRegDialog').hide();"

基本上只有在没有验证失败的情况下才关闭对话框。注意:确保不要 update="" 包含对话框的表单,否则您的对话框每次都会关闭。您应该只更新对话框“cmpRegistration”内的面板,就像我在上面所做的那样。

【讨论】:

猜你喜欢
  • 2012-12-28
  • 2015-03-09
  • 2023-04-03
  • 1970-01-01
  • 2014-08-12
  • 2013-06-14
相关资源
最近更新 更多