Best Practice: Modal Dialog with <p:messages/>?

UI Components for JSF
Post Reply
Strider
Posts: 70
Joined: 03 Dec 2009, 22:24

27 Jan 2010, 20:14

Hi,
i have som dialogs with input fields, for example a name or similar. These fields are marked as required. So if i submit the dialog and close it via oncomplete the error message which is within the dialog is not displayed. I'm looking for a solution that the dialog not closes when a validation error happens. How can i do it?

Here is an example code:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Facelet Title</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <p:resources/>
    </h:head>
    <h:body>
        Hello from Facelets
        <h3>Events</h3>
        <h:form prependId="false">
            <p:commandLink id="submit" oncomplete="dialog.show();" >
                <h:outputText value="Open dialog"/>
            </p:commandLink>
        </h:form>
        <h:form prependId="false">
            <p:dialog header="Testdialog" widgetVar="dialog" fixedCenter="true" modal="true" draggable="false"
                      effect="fade" effectDuration="0.3" id="testDialog">
                <h:panelGrid id="testGrid" columns="2"  >
                    <h:outputText value="Enter value:" />
                    <h:inputText id="value" value="#{pprBean.firstname}" required="true"/>
                    <f:facet name="footer">
                        <h:panelGroup>
                            <p:commandButton action="#{pprBean.doSomething}" id="action" value="Submit" oncomplete="dialog.hide();"/>
                        </h:panelGroup>
                    </f:facet>
                </h:panelGrid>
                <p:messages/>
            </p:dialog>     
        </h:form>
    </h:body>
</html>

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

28 Jan 2010, 14:05

One solution is;

http://www.martinahrer.at/blog/2009/12/ ... available/

Another solution is to pass a callback parameter like 'validationFailed' to your oncomplete javascript handler and decide to hide or keep the dialog open depending on the callback value;

http://www.primefaces.org:8080/prime-sh ... Params.jsf

Strider
Posts: 70
Joined: 03 Dec 2009, 22:24

30 Jan 2010, 14:32

The second solution with the callback is cool and the best for my case. Because i have more than one form on a page. Thx!

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

31 Jan 2010, 17:28

Nice as my primary motivation to implement RequestContext callbacks is to solve this use case, whether or not to hide dialog after an ajax response. :) There're other scenarios where it could be handy as well.

condor
Posts: 13
Joined: 07 Apr 2010, 10:58
Location: Ukraine

07 Apr 2010, 11:13

Hi!
One short question.
Can I use Primefaces RequestContext with h:commandButton + f:ajax instead of p:commandButton?
Primefaces 3.0.M3, Mojarra 2.1.3, Glassfish 3.1.1

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

07 Apr 2010, 12:21

By the way, I provided a solution in the neighbour post based on RequestContext and callback parameters http://primefaces.prime.com.tr/forum/vi ... f=3&t=1901
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

07 Apr 2010, 15:29

No, request callback arguments is a PrimeFaces exclusive feature.

Issue with Oleg's solution might be, his action will not be executed if JSF component validations fails, upcoming args.validationFailed will also cover that.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 36 guests