You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Gregory F. March" <ma...@gfm.net> on 2003/06/06 20:50:50 UTC

DynaValidatorForm setup

Hi all,

I am about to embark on learning about the validation features of
struts.  I currently have a dynamic form (configured in struts-config)
used as a wizard interface and I would like to validate several of
those fields.

I am reading the O'Reilly book _Programming Jakarta Struts_ and I'm
confused about what I need to do.

The book refers to a files called "validation.xml" and about setting
up the plugin.  I am using struts 1.1 and I don't have a
validation.xml file.  I do have a validator-rules.xml and several
dtd's that have DEPRECATED all through out them.

My question is, if I want to add a "formset" (as described on page
272), where do I put it?  Do I need to set up a plug in?

Also, what are those "arg0's" pointing to?

As an aside, has anyone else found that this book covers a lot of
bredth, but not nearly enough depth?  Every time I start working on
part of my project, the book leads me in a certain direction, but
falls short of actually getting there.  Thank goodness for this list
and the archives...

Cheers,

/greg

--
Gregory F. March    -=-    http://www.gfm.net:81/~march    -=-    AIM:GfmNet

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


Re: DynaValidatorForm setup

Posted by Barry Volpe <st...@childrencare.com>.
I was able to piece it all together using the

struts-validator.war file that comes in the

jakarta-struts-1.1-b2 release.


But here is some highlights......

For struts 1.1 in your struts-config.xml you require...

<!--
     Add multiple validator resource files by setting the pathnames property
     with a comma delimitted list of resource files to load.
  -->
 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                 /WEB-INF/validation.xml"/>
 </plug-in>


Here is an example validation.xml  (should be in struts-validate.war file)
Add/edit this file for your particular form:

<global>
      <constant>
        <constant-name>phone</constant-name>






  <constant-value>^\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})$</constant-value>
      </constant>
      <constant>
        <constant-name>zip</constant-name>
        <constant-value>^\d{5}\d*$</constant-value>
      </constant>
   </global>
 <formset>
      <constant>
        <constant-name>zip</constant-name>
        <constant-value>^\d{5}(-\d{4})?$</constant-value>
      </constant>
 <form    name="userForm">
    <field    property="email"
             depends="required,email">
              <arg0 key="userForm.email.displayname"/>
 </field>
 <field    property="firstname"
         depends="required,mask,minlength">
         <arg0 key="userForm.firstname.displayname"/>
         <arg1 name="minlength" key="${var:minlength}" resource="false"/>
         <var>
           <var-name>mask</var-name>
           <var-value>^\w+$</var-value>
         </var>
         <var>
           <var-name>minlength</var-name>
           <var-value>3</var-value>
         </var>
         </field>
   <field    property="lastname"
         depends="required,mask,maxlength">
           <arg0 key="userForm.lastname.displayname"/>
           <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
                 <var>
                   <var-name>mask</var-name>
                   <var-value>^[a-zA-Z]*$</var-value>
                 </var>
                 <var>
                   <var-name>maxlength</var-name>
                   <var-value>10</var-value>
                 </var>
     </field>
   <field    property="address1"
             depends="required">
               <arg0 key="userForm.address1.displayname"/>
         </field>
   <field    property="city"
             depends="required,mask">
               <arg0 key="userForm.city.displayname"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>^[a-zA-Z\s]*$</var-value>
                     </var>
         </field>
         <field    property="state"
             depends="required,mask">
               <arg0 key="userForm.state.displayname"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>^[a-zA-Z]*$</var-value>
                     </var>
         </field>
   <field    property="zip"
             depends="required,mask">
               <arg0 key="userForm.zip.displayname"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>${zip}</var-value>
                     </var>
         </field>
   <field    property="phone"
             depends="required,mask">
               <arg0 key="userForm.phone.displayname"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>${phone}</var-value>
                     </var>
         </field>
   <field    property="password"
             depends="required,password">
              <arg0 key="userForm.password.displayname"/>
 </field>
</form>

<form    name="userPasswordForm">
    <field    property="email"
             depends="required,email">
              <arg0 key="userForm.email.displayname"/>
 </field>
</form>

</formset>
</form-validation>

The validator-rules.xml file has just about every rule you would need for
standard
validation.  It is long so I don't supply it here (in struts-validator.war).


Barry




----- Original Message -----
From: "Gregory F. March" <ma...@gfm.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, June 06, 2003 11:50 AM
Subject: DynaValidatorForm setup


>
> Hi all,
>
> I am about to embark on learning about the validation features of
> struts.  I currently have a dynamic form (configured in struts-config)
> used as a wizard interface and I would like to validate several of
> those fields.
>
> I am reading the O'Reilly book _Programming Jakarta Struts_ and I'm
> confused about what I need to do.
>
> The book refers to a files called "validation.xml" and about setting
> up the plugin.  I am using struts 1.1 and I don't have a
> validation.xml file.  I do have a validator-rules.xml and several
> dtd's that have DEPRECATED all through out them.
>
> My question is, if I want to add a "formset" (as described on page
> 272), where do I put it?  Do I need to set up a plug in?
>
> Also, what are those "arg0's" pointing to?
>
> As an aside, has anyone else found that this book covers a lot of
> bredth, but not nearly enough depth?  Every time I start working on
> part of my project, the book leads me in a certain direction, but
> falls short of actually getting there.  Thank goodness for this list
> and the archives...
>
> Cheers,
>
> /greg
>
> --
> Gregory F. March    -=-    http://www.gfm.net:81/~march    -=-
AIM:GfmNet
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>



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