myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gerald Müllan" <bierbra...@gmail.com>
Subject Re: scripts..
Date Mon, 10 Apr 2006 19:57:26 GMT
Hi,

if you are using myfaces, have a look at the sandbox inputAjax component.

You can do server side validation with it, triggered through a js
event and an ajax request. Validation code can be put in a special
method of a backing bean and is called after the request.

After the ajax response it is possible to call a js function where you
can put in your code above. Content of the response (xml syntax)
differs if the validation performed well or not.

Works pretty good, i have used it in an application to validate some
user inputs after an onblur() event.

You can also write your own validator for this, but I think it will
not be the right choice for this kind of use case.

Is your update function called, or is there another problem inside the function?

best regards,

Gerald

On 4/10/06, sjarlier@stradefi.com <sjarlier@stradefi.com> wrote:
> I was using my validation on client side in order to show directly errors to
> the user while he is filling the form. How do you do this validation from
> server side?
>
> I have this script and I am calling the function update () when clicking
> changing a button:
>
> <script language="JavaScript1.2" src="formValidation.js"></script>
> <script language="JavaScript1.2" >
>
>    window.onload = pageLoaded;
>
>    function pageLoaded()
>    {
>       document.getElementById("person-props:firstName").focus();
>       updateButtonState();
>    }
>
>    function update ()
>    {
>       var disabled = true;
>
>       //THESE FIELDS HAVE TO BE FILLED TO PASS TO NEXT STEP
>       if (document.getElementById("person-props:firstName").value.length ==
> 0 ||
>           document.getElementById("person-props:lastName").value.length == 0
> ||
>           document.getElementById("person-props:email").value.length == 0 ||
>
> document.getElementById("person-props:activationDate").value.length == 0)
>       {
>          disabled = true;
>       }
>       else
>       {
>          disabled = false;
>       }
>
>       //THIS FIELD SHOULD BE AN EMAIL ...@...
>
> if(isNotEmailAdress(document.getElementById("person-props:email").value)){
>         disabled = true;
>         document.getElementById("person-props:email").className =
> "errorMessage";
>       }
>       else{
>         document.getElementById("person-props:email").className =
> "textFields";
>       }
>
>       //THESE FIELDS SHOULD BE OF TYPE STRING
>       if(document.getElementById("person-props:firstName").value.length !=
> 0)
>       {
>         if
> (isNotAlphabetic(document.getElementById("person-props:firstName").value)){
>                 disabled = true;
>                 document.getElementById("person-props:firstName").className
> = "errorMessage";
>         }
>         else{
>
> document.getElementById("person-props:firstName").className= "textFields";
>
>         }
>       }
>       if(document.getElementById("person-props:lastName").value.length!=0)
>       {
>         if
> (isNotAlphabetic(document.getElementById("person-props:lastName").value)){
>                 disabled = true;
>                 document.getElementById("person-props:lastName").className =
> "errorMessage";
>         }
>         else{
>                 document.getElementById("person-props:lastName").className=
> "textFields";
>         }
>       }
>
>       if(document.getElementById("person-props:secondName").value.length!=0)
>       {
>        if
> (isNotAlphabetic(document.getElementById("person-props:secondName").value)){
>                 disabled = true;
>                 document.getElementById("person-props:secondName").className
> = "errorMessage";
>         }
>         else{
>
> document.getElementById("person-props:secondName").className= "textFields";
>         }
>       }
>
>       if(document.getElementById("person-props:town").value.length!=0)
>       {
>        if
> (isNotAlphabetic(document.getElementById("person-props:town").value)){
>                 disabled = true;
>                 document.getElementById("person-props:town").className =
> "errorMessage";
>         }
>         else{
>                 document.getElementById("person-props:town").className=
> "textFields";
>         }
>       }
>
>           //CHECK PHONE NUMBERS
>           if(document.getElementById("person-props:telPro").value.length!=0)
>       {
>        if
> (isNotTelephone(document.getElementById("person-props:telPro").value,"inte")
> ){
>                 disabled = true;
>                 document.getElementById("person-props:telPro").className =
> "errorMessage";
>         }
>         else{
>                 document.getElementById("person-props:telPro").className=
> "textFields";
>         }
>       }
>
>       //ACCORDING TO LAST RESULTS DISABLE OR NOT NEXT BUTTON
>       document.getElementById("person-props:next-button").disabled =
> disabled;
>
>    }
>
> </script>
>
> Thanks
>
> -----Message d'origine-----
> De: Gerald Müllan [mailto:bierbrauen@gmail.com]
> Envoyé: lundi 10 avril 2006 18:11
> À: MyFaces Discussion
> Objet: Re: scripts..
>
> Hi,
>
> is it a need to do this validation on client side? How do you trigger
> the js check?
>
> If you say "nothing works", it is difficult to respond what could be
> wrong. What is the exact problem?
>
> cheers,
>
> Gerald
>
> On 4/10/06, sjarlier@stradefi.com <sjarlier@stradefi.com> wrote:
> > Hi!
> >
> > I am stuck with my scripts. I would like to check if my dates are correct:
> >  - The entered date is really a date
> >  - The entered date is the date of the current date or a later date
> >
> > I am getting the date using Jenia4Faces as follow:
> >
> > <td colspan="2">
> >    <h:outputText value="#{EFmsg.activationDate}"/>:&nbsp;&nbsp;&nbsp;
> >    <h:inputText
> > value="#{EF_JspWizard.jspFormEPPService.pers_activationDate}" size="10"
> > id="activationDate" required="true" >
> >    <f:convertDateTime pattern="dd/MM/yyyy"/>
> >    </h:inputText>&nbsp;
> >    <jp:popupCalendar for="activationDate" format="dd/MM/yyyy" />&nbsp;*
> > </td>
> >
> >
> > And I am testing if the date obtained is present day or late as follow:
> >
> > function isFutureOrPresentDate(valeur)
> > {
> >       var now = new Date();
> >         var now_day = now.getDay();
> >         var now_month = now.getMonth();
> >         var now_year = now.getYear();
> >
> >       if(valeur.getYear()>now_year)
> >             return true;
> >       else if(valeur.getYear()==now_year)
> >             if(valeur.getMonth()>now_month)
> >                   return true;
> >             else if(valeur.getMonth()==now_month)
> >                   if(valeur.getDay()>now_day || valeur.getDay()==now_day)
> >                         return true;
> >                     else
> >                         return false;
> >                  else return false;
> >            else
> >             return false;
> > }
> >
> >
> > And I am checking if the entrance is really a date as follow:
> >
> > function CheckDate(d) {
> >
> >       // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité
> de
> > la date.
> >       // Le séparateur est défini dans la variable separateur
> >
> >       var amin=1900; // année mini
> >       var amax=2100; // année maxi
> >       var separateur="/"; // separateur entre jour/mois/annee
> >       var j=(d.substring(0,2));
> >       var m=(d.substring(3,5));
> >       var a=(d.substring(6));
> >       var ok=1;
> >       if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
> >          alert("Le jour n'est pas correct."); ok=0;
> >       }
> >       if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
> >          alert("Le mois n'est pas correct."); ok=0;
> >       }
> >       if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
> >          alert("L'année n'est pas correcte."); ok=0;
> >       }
> >       if (
> ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur))
> > && (ok==1) ) {
> >          alert("Les séparateurs doivent être des "+separateur); ok=0;
> >       }
> >       if (ok==1) {
> >          var d2=new Date(a,m-1,j);
> >          j2=d2.getDate();
> >          m2=d2.getMonth()+1;
> >          a2=d2.getFullYear();
> >          if (a2<=100) {a2=1900+a2}
> >          if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
> >             alert("La date "+d+" n'existe pas !");
> >             ok=0;
> >          }
> >       }
> >
> >       return ok;
> >    }
> >
> > And I am calling the function to check if the date is present or future
> date
> > as follow:
> >
> >
> if(isFutureOrPresentDate(document.getElementById("person-props:activationDat
> > e").value)){
> >
> >
> > document.getElementById("person-props:activationDate").className=
> > "textFields";
> >
> >             }
> > else{
> >           disabled = true;
> >           document.getElementById("person-props:activationDate").className
> =
> > "errorMessage";
> >             }
> >       }
> >
> >  But nothing works. What do I do wrong?
> > Thanks in advance
> > Have a nice week!
> >
> > Sophie
> >
> >
> >
>
>
> --
> Gerald Müllan
> Schelleingasse 2/11
> 1040 Vienna, Austria
> 0043 699 11772506
> Bierbrauen@gmail.com
>
>


--
Gerald Müllan
Schelleingasse 2/11
1040 Vienna, Austria
0043 699 11772506
Bierbrauen@gmail.com

Mime
View raw message