0
votes

I have a simple page with data table. Above the table theres a button to add a new table row. This button opens up a pop up form with the registration form. The object which is being created in that form has a bean validation set. Now when I submit an invalid form, the data is not added, a message is created and the pop up window is closed.

My problem is that I want to keep the pop up window open in case the validation is not passed.

The pop up window code:


<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>
1
Copy pasting your title in a search engine (even without adding site:stackoverflow.com) I got stackoverflow.com/questions/9195756/…Kukeltje

1 Answers

2
votes

Yep just add this to your "Submit" button 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();"

Basically only close the dialog if there was no validation failure. NOTE: Make sure not to update="" the form enclosing the dialog or else your dialog will close every time. You should only update the panel inside the dialog "cmpRegistration" like I have done above.