You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by david chan <da...@yahoo.com> on 2002/12/18 21:01:04 UTC

validate one field in multipage

Hi,
 I am using Struts-1.1b2 client side validator. And I
have a big form for multipage user input. One of the
field need to validated in page 1 and  2. But I don't
see how can I do that, or does anyone know how to do
it? Here is my config:
validator.xml:
        <field property="firstnm"
                depends="required,maxlength"
                page="1">
                <arg0     key="prompt.firstnm"/>
        ...

in my JSP:
...
<html:javascript formName="caseForm"  page="1"/>
...

And this will lock the validation of firstnm field in
page 1 only, it won't show up in page 2.

Can I specify more than one page validation like this:

        <field property="firstnm"
                depends="required,maxlength"
                page="1,2">
                <arg0     key="prompt.firstnm"/>


Thanks.
David

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: validate one field in multipage

Posted by Derek Lin <de...@hotmail.com>.
David,

I saw this email after I sent you my previous reply.  Anyway, like I said, I
am against the page attribute because it locks your form fields to certain
page.  My approach is to modify the validation code:
For example:
In Java:
    public static boolean validateRequired(Object bean,
                                            ValidatorAction va,
                                            Field field,
                                            ActionErrors errors,
                                            HttpServletRequest request) {
        if (field == null || bean == null) {
           return true;
        }
        String value = null;
        if (isString(bean)) {
            value = (String) bean;
        } else {
            value = ValidatorUtil.getValueAsString(bean,
field.getProperty());
        }
        if (value == null) {
            return true;
        }
        value = value.trim();
        if (GenericValidator.isBlankOrNull(value)) {
            errors.add(field.getKey(),
                       StrutsValidatorUtil.getActionError(request, va,
field));

            return false;
        } else {
            return true;
        }
    }

In JavaScript:
         <javascript><![CDATA[
            function validateRequired(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oRequired = new futurecargorequired();
                for (x in oRequired) {
                  if (form[oRequired[x][0]] != null) {
                    if ( (form[oRequired[x][0]].type == 'text' ||
                         form[oRequired[x][0]].type == 'textarea' ||
                         form[oRequired[x][0]].type == 'select-one' ||
                         form[oRequired[x][0]].type == 'radio' ||
                         form[oRequired[x][0]].type == 'password') &&
                        (trim(form[oRequired[x][0]].value) == '')) {
                        if (i == 0) {
                            focusField = form[oRequired[x][0]];
                        }
                        fields[i++] = oRequired[x][1];
                        bValid = false;
                    }
          form[oRequired[x][0]].value = trim(form[oRequired[x][0]].value);
                  }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }
...

Maybe you can rewrite them to make them more elegant.

-- Derek

----- Original Message -----
From: "david chan" <da...@yahoo.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, December 18, 2002 12:01 PM
Subject: validate one field in multipage


> Hi,
>  I am using Struts-1.1b2 client side validator. And I
> have a big form for multipage user input. One of the
> field need to validated in page 1 and  2. But I don't
> see how can I do that, or does anyone know how to do
> it? Here is my config:
> validator.xml:
>         <field property="firstnm"
>                 depends="required,maxlength"
>                 page="1">
>                 <arg0     key="prompt.firstnm"/>
>         ...
>
> in my JSP:
> ...
> <html:javascript formName="caseForm"  page="1"/>
> ...
>
> And this will lock the validation of firstnm field in
> page 1 only, it won't show up in page 2.
>
> Can I specify more than one page validation like this:
>
>         <field property="firstnm"
>                 depends="required,maxlength"
>                 page="1,2">
>                 <arg0     key="prompt.firstnm"/>
>
>
> Thanks.
> David
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>