Sathish Robert
Sathish Robert

Reputation: 187

JSF validation Message Display in Dialog Box when Button click

I need for JSF validation messages displaying in Dialog box when Button is clicked but dialog box should be shown not get hidden.

<h:form prependId="false">
    <h:panelGrid  columns="1" cellpadding="5">
        <p:commandButton value="Modal" onclick="dlg2.show();" type="button" />
    </h:panelGrid>

<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" height="200" width="400">
    <h:panelGrid columns="1" >
    <p:messages />
    <p:inputText id="txt" value="#{converterBean.doubleValue}" required="true"/>
    <p:commandButton ajax="false" value="Submit" action="#{converterBean.submit}" />
    </h:panelGrid>
</p:dialog>



    </h:form>

Upvotes: 2

Views: 19394

Answers (2)

Matt Handy
Matt Handy

Reputation: 30025

Your case is very similar to this example from the primefaces showcase.

Notice that <h:form> is inside <p:dialog> there. Also notice in the example's LoginBean.java how the callback parameter is set.

Change the <p:commandButton> that it updates your <p:messages> (it updates a <p:growl> in the example.

Upvotes: 3

cord
cord

Reputation: 11

Well, there is an option in called process, you can process only certain fields for example what appears below will only submit data under someID only, not the whole entire form

        <p:dialog id="dialog" header="Login" widgetVar="dlg" width="600" >

            <h:panelGrid columns="3" cellpadding="5" id="someID">
                <h:outputLabel for="username" value="Username: *" />
                <p:inputText
                    id="username" required="true" label="username" requiredMessage="Field required" />
                <p:message for="username"/>

                <h:outputLabel for="password" value="Password: * " />
                <h:inputSecret
                    id="password" required="true" label="password"  requiredMessage="Field required"  />
                <p:message for="password"/>

                <f:facet name="footer">
                    <p:commandButton value="Login" update="display" process="someID" onsuccess="dlg.hide()" onerror="dlg.show()" />
                </f:facet>
            </h:panelGrid>
        </p:dialog>

Upvotes: 1

Related Questions