struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Winterfeldt <dwinterfe...@yahoo.com>
Subject RE: Questions About Struts Validator
Date Thu, 11 Oct 2001 19:16:36 GMT
For Q2:
You can override the default validator's error message
by specifying a msg element or you can change the
defult of course.

 <field    property="lastName"
 	   depends="required,mask">
 	     <msg name="mask"
key="registrationForm.lastname.maskmsg"/>
 	     <arg0
key="registrationForm.lastname.displayname"/>
             <var>
               <var-name>mask</var-name>
               <var-value>^[a-zA-Z]*$</var-value>
             </var>         	   
 </field>

You can also specify different arguments to go with
different errors.

 <field    property="integer"
 	   depends="required,integer,range">
 	     <arg0 key="typeForm.integer.displayname"/>
 	     <arg1 name="range" key="${var:min}"
resource="false"/>
 	     <arg2 name="range" key="${var:max}"
resource="false"/>
             <var>
               <var-name>min</var-name>
               <var-value>10</var-value>
             </var>         	   
             <var>
               <var-name>max</var-name>
               <var-value>20</var-value>
             </var>         	   
 </field>

David


--- Vaughan Jackson <vaughan.jackson@tumbleweed.com>
wrote:
> David,
> 
> Thanks for your feedback. 
> 
> I will try out the technique you describe for Q1. 
> 
> I could have phrased Q2 better: "... and have a
> different 
> error message resulting according to which rule(s)
> is/are
> broken?".
> 
> Yes, you have told me what I wanted to know for Q3.
> 
> Vaughan.
> 
> > -----Original Message-----
> > From: David Winterfeldt
> [mailto:dwinterfeldt@yahoo.com]
> > Sent: Thursday, October 11, 2001 10:36 AM
> > To: struts-user@jakarta.apache.org
> > Subject: Re: Questions About Struts Validator
> > 
> > 
> > 
> > --- Vaughan Jackson
> <vaughan.jackson@tumbleweed.com>
> > wrote:
> > > Hi,
> > > 
> > > Three questions in fact. Some variants on these
> came
> > > up earlier,
> > > but we would like to know whether the
> > > Struts1.0-compatible version
> > > makes any of the below possible, or whether
> support
> > > for them is coming.
> > The 7/2/2001 was the last build compatible with
> the
> > Struts 1.0 release.  It can be downloaded from
> > http://home.earthlink.net/~dwinterfeldt/.
> > 
> > > 
> > > 1. Is there any way to have multiple
> > > validation.xml-type files 
> > >    associated with a single web application?
> > Yes, but it isn't a build in feature.  The
> > ValidatorServlet calls
> ValidatorResourcesInitializer
> > which has an initialize method which returns a
> > ValidatorResources object and then the
> > ValidatorResources object is put into application
> > scope.  When the ValidatorForm's validate method
> is
> > called the resource is retrieved and set along
> with
> > some other variables to configure the Validator
> class.
> >  So you would just have to write something that
> loads
> > multiple validation files and puts them somewhere
> in
> > scope.  Then the ActionForm/ValidatorForm
> (whichever
> > you subclass) would need to know which
> > ValidatorResources to retrieve from scope. 
> Otherwise
> > the code would be the same.
> > 
> > > 2. Is there any way to associate more than one
> > > (server-side) 
> > >     validation rule with the same field?
> > The depends attribute can have as many
> > validation/validator references you want.
> > 
> >  <field    property="zipPostal"
> >  	   depends="required,mask"
> >            page="2">
> >  	     <arg0
> > key="registrationForm.zippostal.displayname"/>
> >              <var>
> >                <var-name>mask</var-name>
> >                <var-value>${zip}</var-value>
> >              </var>
> >  </field>
> > 
> > 
> > > 3. Is it possible to associate the validation
> > > directly with the 
> > >     field involved, without having to refer to
> it
> > > within the context of 
> > >     a given form?
> > I'm not sure what you mean exactly.  What do you
> mean
> > by directly associate a field?  Are you asking if
> you
> > can always have the field name have a certain
> > validation?  You can't do that currently.  You
> need to
> > the define the rules for each form, but you don't
> need
> > to keep defining them for locale.  
> > 
> > Hope this helps.
> > 
> > David
> > 
> > > 
> > > Thanks,
> > > Vaughan.
> > >
> ___________________________________________________
> > > Vaughan Jackson
> > > Development 
> > > Tumbleweed Communications
> > > vaughan.jackson@tumbleweed.com / +1 (650) 216
> 2532
> > >
> ___________________________________________________
> > > 
> > > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Make a great connection at Yahoo! Personals.
> > http://personals.yahoo.com
> > 
> 


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

Mime
View raw message