Validation

UI Components for JSF
Post Reply
vuimotti
Posts: 5
Joined: 14 Aug 2011, 19:28

19 Aug 2011, 21:18

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>Show</title>
        <link type="text/css" rel="stylesheet" href="Css/default.css" />
        <script type="text/javascript">
                function onInsertComplete(xhr, status, args) {
                    if(args.validationFailed || !args.flag) {
                        $(PrimeFaces.escapeClientId('form:dialog')).parent().effect("shake", { times:5 }, 100);
                    } else {
                        dlg.hide();
                    }
                }
        </script>
    </h:head>
    <h:body>
        <p:growl id="growl" showDetail="true" life="3000" /> 
        <f:view>
            <h:form id="form" style="text-align: center" >
                <p:commandButton value="Insert" title="Insert" image="ui-icon ui-icon-disk" oncomplete="dlg.show()" />
               <p:dialog id="dialog" header="Login" widgetVar="dlg">
                    <h:panelGrid columns="2" cellpadding="4" style="text-align: center;">
                        <h:outputLabel value="Username:" />
                        <h:inputText id="username" value="#{userBean.userTbl.username}"/>
                        <h:outputLabel value="Password:" />
                        <h:inputText id="password" value="#{userBean.userTbl.password}"/>
                        <h:outputLabel value="Address:"  />
                        <h:inputText id="address" value="#{userBean.userTbl.address}"/>
                        <h:outputLabel value="TblGroup:" />
                        <h:selectOneMenu id="tblGroup" value="#{userBean.userTbl.tblGroup}">
                            <!-- TODO: update below reference to list of available items-->
                            <f:selectItems value="#{userBean.groupList}"/>
                        </h:selectOneMenu>
                        <p:commandButton value="Save" actionListener="#{userBean.insert}" update="growl"
                                         oncomplete="onInsertComplete(xhr, status, args)"/>
                    </h:panelGrid>
                </p:dialog>
            </h:form>
        </f:view>
    </h:body>
</html>

Code: Select all

public void insert(ActionEvent actionEvent) {
            RequestContext context = RequestContext.getCurrentInstance();
            FacesMessage msgs = null;
            boolean flag = false;
            if (userTbl.getUsername().trim().equals("")) {
                flag = false;
                msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid User Name", "User Name can't null !");
            } else if (userTbl.getPassword().trim().equals("")) {
                flag = false;
                msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Password", "Password can't null !");
            } else if (userTbl.getAddress().trim().equals("")) {
                flag = false;
                msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Address", "Address can't null !");
            } else {
                userSessionLc.insertUser(userTbl);
                flag = true;
                msgs = new FacesMessage(FacesMessage.SEVERITY_INFO, "OK", "Insert successful !");
            }
            FacesContext.getCurrentInstance().addMessage(null, msgs);
            context.addCallbackParam("insert", flag);
    }
when args.validationFailed is true anf args.flag = true Dialog dlg don't close.

Please Help me.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

19 Aug 2011, 21:36

Did you checked possible javascript errors?
Maybe dlg isnt defined at this level... you should move that script to the bottom
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

vuimotti
Posts: 5
Joined: 14 Aug 2011, 19:28

20 Aug 2011, 10:59

Script is from http://www.primefaces.org/showcase-labs ... Column.jsf. When you Edit validation error
I do not know any alternative for this.

vuimotti
Posts: 5
Joined: 14 Aug 2011, 19:28

20 Aug 2011, 11:19

I test Script

Code: Select all

<script type="text/javascript">
                function onInsertComplete(xhr, status, args) {
                    if(args.validationFailed || !args.flag) {
                        $(PrimeFaces.escapeClientId('form:dialog')).parent().effect("shake", { times:5 }, 100);
                    } else {
                        alert("Don't hide");
                        dlg.hide();
                    }
                }
        </script>
alert is show and dlg.hide() don't run.

Code: Select all

<script type="text/javascript">
                function onInsertComplete(xhr, status, args) {
                    if(args.validationFailed || !args.flag) {
                        $(PrimeFaces.escapeClientId('form:dialog')).parent().effect("shake", { times:5 }, 100);
                    } else 
                        dlg.hide();
                         alert("Don't hide");
                    }
                }
        </script>

alert("Don't hide") don't show. dlg.hide() that is not running. I think by widgetVar. So how do I do to hide that dialog when I valiation success.
I so need to resolve the issue. I use it in my graduation project.
Please help me !
Thanks all.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

20 Aug 2011, 11:36

did you tried to move the script from head to the page bottom like i said in my last post?
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

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

20 Aug 2011, 12:56

Hi
when args.validationFailed is true anf args.flag = true Dialog dlg don't close.
Did you mean args.validationFailed is false? If args.validationFailed is true, the dialog can't be closed according to your logic in JS snippet. And you put your flag variable under key "insert", so that the right if-statement would be

Code: Select all

if(args.validationFailed || !args.insert) {
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

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests