You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chetan Pandey <cp...@BLUEsingapore.com> on 2006/08/02 03:54:56 UTC

Client Side Validation

Hi All:

 

I am trying to do Client-Side Validation for my JSP Form:

 

<html:javascript formName="AttendeeDetailsForm"/>

 

<html:errors/>

 

 

 

<html:form action="/addAttendeeDetails">

.

.

.

.

</html:form>

 

 

But the problem is I only see Server Side Validations no Client Side
Validations.

 

This is the Validator I am using which I copied from the Net:

 

/***************************************************************************
********************/

<validator name="required"

            classname="org.apache.struts.validator.FieldChecks"

               method="validateRequired"

         methodParams="java.lang.Object,

                       org.apache.commons.validator.ValidatorAction,

                       org.apache.commons.validator.Field,

                       org.apache.struts.action.ActionMessages,

                       org.apache.commons.validator.Validator,

                       javax.servlet.http.HttpServletRequest"

                  msg="errors.required">

        <javascript><![CDATA[

            function validateRequired(form) {

                var isValid = true;

                var focusField = null;

                var i = 0;

                var fields = new Array();

                oRequired = new required();

                for (x in oRequired) {

                  var field = form[oRequired[x][0]];

                  

                    if (field.type == 'text' ||

                        field.type == 'textarea' ||

                        field.type == 'file' ||

                        field.type == 'select-one' ||

                        field.type == 'radio' ||

                        field.type == 'password') {

                        

                        var value = '';

                                    // get field's value

                                    if (field.type == "select-one") {

                                          var si = field.selectedIndex;

                                          if (si >= 0) {

                                                value =
field.options[si].value;

                                          }

                                    } else {

                                          value = field.value;

                                    }

                        

                        if (trim(value).length == 0) {

                        

                              if (i == 0) {

                                  focusField = field;

                              }

                              fields[i++] = oRequired[x][1];

                              isValid = false;

                        }

                    }

                }

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));

                }

                return isValid;

            }

            

            // Trim whitespace from left and right sides of s.

            function trim(s) {

                return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );

            }

            

            ]]>

         </javascript>           

    </validator>

 

/***************************************************/

 

 

Does anyone have any Idea why I don't see Client Side Validation


RE: Client Side Validation

Posted by Chetan Pandey <cp...@BLUEsingapore.com>.
I have changed the name to attendeeDetailsForm everywhere as you have
suggested

And have 
html:form action="/addAttendeeDetails" onsubmit="return
 validateAttendeeDetailsForm(this)">

But this is not helping me still.

I only get Server side validation, no Client Side Validation.

Thanks.

Chetan Pandey



-----Original Message-----
From: Irwan Nurwandi [mailto:irwan.nurwandi@gmail.com] 
Sent: Thursday, August 03, 2006 2:13 PM
To: Struts Users Mailing List
Subject: Re: Client Side Validation

Dear Chetan

Look at your bean form definition in your validation.xml

if you specify the form bean like this :

<formset>
	<form name="attendeeDetailsForm">
        </form>
</formset>

then you should call generated javascript with this

<html:javascript formName="attendeeDetailsForm"/>

the first letter in form bean name shouls be in lowercase also...

HTH
Irwan

On 8/3/06, Chetan Pandey <cp...@bluesingapore.com> wrote:
> Hi All:
>
> This is what I am doing.
>
> <html:form action="/addAttendeeDetails" onsubmit="return
> validateAttendeeDetailsForm(this)">
> .
> .
> .
> .
> .
> .
> <html:javascript formName="AttendeeDetailsForm"/>
> </html:form>
>
>
> But the Code only does Server Side Validation.
>
> Am I missing naything pls.
>
> Thanks.
>
> Chetan Pandey
>
> -----Original Message-----
> From: Romu [mailto:romu31@gmail.com]
> Sent: Wednesday, August 02, 2006 3:28 PM
> To: Struts Users Mailing List
> Subject: Re: Client Side Validation
>
> your form shoud have been named :
> attendeeDetailsForm, like bean no caps for first letter .
>
> then
> validateAttendeeDeta
> >
> > onsubmit="validateAttendeeDeta
> > >
> > > ilsForm ();
> >
> >  or
> validateAttendeeDeta
> >
> > onsubmit="validateAttendeeDeta
> > >
> > > ilsForm (this);
> > >
> >
> u can see the javascript generated in the source of your jsp btw .
> hope it helps
>
>
>
>
>
>
> 2006/8/2, Chetan Pandey <cp...@bluesingapore.com>:
> >
> > I have this:
> >
> > <html:form action="/addAttendeeDetails"  onsubmit="return
> > validateRequired(this)">
> >
> > Where "validateRequired" comes from the following Javascript code in my
> > validator-rules.xml
> >
> > <validator name="required"
> >             classname="org.apache.struts.validator.FieldChecks"
> >                method="validateRequired"
> >          methodParams="java.lang.Object,
> >                        org.apache.commons.validator.ValidatorAction,
> >                        org.apache.commons.validator.Field,
> >                        org.apache.struts.action.ActionMessages,
> >                        org.apache.commons.validator.Validator,
> >                        javax.servlet.http.HttpServletRequest"
> >                   msg="errors.required">
> >
> >
> >         <javascript><![CDATA[
> >             function validateRequired(form) {
> > ....
> > }
> >       ]]>
> >          </javascript>
> >     </validator>
> >
> > But no Client-side Validation is occuring
> >
> > -----Original Message-----
> > From: Lixin Chu [mailto:lixin.chu@gmail.com]
> > Sent: Wednesday, August 02, 2006 10:35 AM
> > To: Struts Users Mailing List
> > Subject: Re: Client Side Validation
> >
> > do you have something like:
> > onsubmit="validateAttendeeDetailsForm (this);"
> > in <html:form> ?
> >
> > and form name is not attendeeDetailsForn ?
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Client Side Validation

Posted by Irwan Nurwandi <ir...@gmail.com>.
Dear Chetan

Look at your bean form definition in your validation.xml

if you specify the form bean like this :

<formset>
	<form name="attendeeDetailsForm">
        </form>
</formset>

then you should call generated javascript with this

<html:javascript formName="attendeeDetailsForm"/>

the first letter in form bean name shouls be in lowercase also...

HTH
Irwan

On 8/3/06, Chetan Pandey <cp...@bluesingapore.com> wrote:
> Hi All:
>
> This is what I am doing.
>
> <html:form action="/addAttendeeDetails" onsubmit="return
> validateAttendeeDetailsForm(this)">
> .
> .
> .
> .
> .
> .
> <html:javascript formName="AttendeeDetailsForm"/>
> </html:form>
>
>
> But the Code only does Server Side Validation.
>
> Am I missing naything pls.
>
> Thanks.
>
> Chetan Pandey
>
> -----Original Message-----
> From: Romu [mailto:romu31@gmail.com]
> Sent: Wednesday, August 02, 2006 3:28 PM
> To: Struts Users Mailing List
> Subject: Re: Client Side Validation
>
> your form shoud have been named :
> attendeeDetailsForm, like bean no caps for first letter .
>
> then
> validateAttendeeDeta
> >
> > onsubmit="validateAttendeeDeta
> > >
> > > ilsForm ();
> >
> >  or
> validateAttendeeDeta
> >
> > onsubmit="validateAttendeeDeta
> > >
> > > ilsForm (this);
> > >
> >
> u can see the javascript generated in the source of your jsp btw .
> hope it helps
>
>
>
>
>
>
> 2006/8/2, Chetan Pandey <cp...@bluesingapore.com>:
> >
> > I have this:
> >
> > <html:form action="/addAttendeeDetails"  onsubmit="return
> > validateRequired(this)">
> >
> > Where "validateRequired" comes from the following Javascript code in my
> > validator-rules.xml
> >
> > <validator name="required"
> >             classname="org.apache.struts.validator.FieldChecks"
> >                method="validateRequired"
> >          methodParams="java.lang.Object,
> >                        org.apache.commons.validator.ValidatorAction,
> >                        org.apache.commons.validator.Field,
> >                        org.apache.struts.action.ActionMessages,
> >                        org.apache.commons.validator.Validator,
> >                        javax.servlet.http.HttpServletRequest"
> >                   msg="errors.required">
> >
> >
> >         <javascript><![CDATA[
> >             function validateRequired(form) {
> > ....
> > }
> >       ]]>
> >          </javascript>
> >     </validator>
> >
> > But no Client-side Validation is occuring
> >
> > -----Original Message-----
> > From: Lixin Chu [mailto:lixin.chu@gmail.com]
> > Sent: Wednesday, August 02, 2006 10:35 AM
> > To: Struts Users Mailing List
> > Subject: Re: Client Side Validation
> >
> > do you have something like:
> > onsubmit="validateAttendeeDetailsForm (this);"
> > in <html:form> ?
> >
> > and form name is not attendeeDetailsForn ?
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Client Side Validation

Posted by Chetan Pandey <cp...@BLUEsingapore.com>.
Hi All:

This is what I am doing.

<html:form action="/addAttendeeDetails" onsubmit="return
validateAttendeeDetailsForm(this)">
.
.
.
.
.
.
<html:javascript formName="AttendeeDetailsForm"/>
</html:form>


But the Code only does Server Side Validation.

Am I missing naything pls.

Thanks.

Chetan Pandey

-----Original Message-----
From: Romu [mailto:romu31@gmail.com] 
Sent: Wednesday, August 02, 2006 3:28 PM
To: Struts Users Mailing List
Subject: Re: Client Side Validation

your form shoud have been named :
attendeeDetailsForm, like bean no caps for first letter .

then
validateAttendeeDeta
>
> onsubmit="validateAttendeeDeta
> >
> > ilsForm ();
>
>  or
validateAttendeeDeta
>
> onsubmit="validateAttendeeDeta
> >
> > ilsForm (this);
> >
>
u can see the javascript generated in the source of your jsp btw .
hope it helps






2006/8/2, Chetan Pandey <cp...@bluesingapore.com>:
>
> I have this:
>
> <html:form action="/addAttendeeDetails"  onsubmit="return
> validateRequired(this)">
>
> Where "validateRequired" comes from the following Javascript code in my
> validator-rules.xml
>
> <validator name="required"
>             classname="org.apache.struts.validator.FieldChecks"
>                method="validateRequired"
>          methodParams="java.lang.Object,
>                        org.apache.commons.validator.ValidatorAction,
>                        org.apache.commons.validator.Field,
>                        org.apache.struts.action.ActionMessages,
>                        org.apache.commons.validator.Validator,
>                        javax.servlet.http.HttpServletRequest"
>                   msg="errors.required">
>
>
>         <javascript><![CDATA[
>             function validateRequired(form) {
> ....
> }
>       ]]>
>          </javascript>
>     </validator>
>
> But no Client-side Validation is occuring
>
> -----Original Message-----
> From: Lixin Chu [mailto:lixin.chu@gmail.com]
> Sent: Wednesday, August 02, 2006 10:35 AM
> To: Struts Users Mailing List
> Subject: Re: Client Side Validation
>
> do you have something like:
> onsubmit="validateAttendeeDetailsForm (this);"
> in <html:form> ?
>
> and form name is not attendeeDetailsForn ?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Client Side Validation

Posted by Romu <ro...@gmail.com>.
your form shoud have been named :
attendeeDetailsForm, like bean no caps for first letter .

then
validateAttendeeDeta
>
> onsubmit="validateAttendeeDeta
> >
> > ilsForm ();
>
>  or
validateAttendeeDeta
>
> onsubmit="validateAttendeeDeta
> >
> > ilsForm (this);
> >
>
u can see the javascript generated in the source of your jsp btw .
hope it helps






2006/8/2, Chetan Pandey <cp...@bluesingapore.com>:
>
> I have this:
>
> <html:form action="/addAttendeeDetails"  onsubmit="return
> validateRequired(this)">
>
> Where "validateRequired" comes from the following Javascript code in my
> validator-rules.xml
>
> <validator name="required"
>             classname="org.apache.struts.validator.FieldChecks"
>                method="validateRequired"
>          methodParams="java.lang.Object,
>                        org.apache.commons.validator.ValidatorAction,
>                        org.apache.commons.validator.Field,
>                        org.apache.struts.action.ActionMessages,
>                        org.apache.commons.validator.Validator,
>                        javax.servlet.http.HttpServletRequest"
>                   msg="errors.required">
>
>
>         <javascript><![CDATA[
>             function validateRequired(form) {
> ....
> }
>       ]]>
>          </javascript>
>     </validator>
>
> But no Client-side Validation is occuring
>
> -----Original Message-----
> From: Lixin Chu [mailto:lixin.chu@gmail.com]
> Sent: Wednesday, August 02, 2006 10:35 AM
> To: Struts Users Mailing List
> Subject: Re: Client Side Validation
>
> do you have something like:
> onsubmit="validateAttendeeDetailsForm (this);"
> in <html:form> ?
>
> and form name is not attendeeDetailsForn ?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: Client Side Validation

Posted by Chetan Pandey <cp...@BLUEsingapore.com>.
I have this:

<html:form action="/addAttendeeDetails"  onsubmit="return
validateRequired(this)">

Where "validateRequired" comes from the following Javascript code in my
validator-rules.xml

<validator name="required"
            classname="org.apache.struts.validator.FieldChecks"
               method="validateRequired"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.required">


        <javascript><![CDATA[
            function validateRequired(form) {
....
}
      ]]>
         </javascript>           
    </validator>

But no Client-side Validation is occuring

-----Original Message-----
From: Lixin Chu [mailto:lixin.chu@gmail.com] 
Sent: Wednesday, August 02, 2006 10:35 AM
To: Struts Users Mailing List
Subject: Re: Client Side Validation

do you have something like:
 onsubmit="validateAttendeeDetailsForm (this);"
in <html:form> ?

and form name is not attendeeDetailsForn ?




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Client Side Validation

Posted by Lixin Chu <li...@gmail.com>.
do you have something like:
 onsubmit="validateAttendeeDetailsForm (this);"
in <html:form> ?

and form name is not attendeeDetailsForn ?