Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: Validation rule writing

Laurie Harper

2006-12-15

Replies:

What Chris said, plus this:

 <field property="areaCode" depends="required, areaCodeMask" ...

there's no validation rule named 'areaCodeMask' or 'phoneMask'; you want
just 'mask' as the rule name. See the validator documentation for examples.

Also, is validation working at all for you? For example, is it correctly
detecting errors for the properties you have marked with just the
'required' rule? If not, start by figuring that out, then worry about
getting your masks applied correctly.

L.

Thom Burnett wrote:
> I'm trying to validate two fields - area code and phone number (as nnn-nnnn
> no areacode in that input).
>
> Various samples and reading suggest that I should be able to create a mask
> and apply it as below but my result is that the area code can't be empty
> but
> it can contain letters, be longer than 3. It's ignoring my regular
> expression mask.
>
> Am I missing something simple in how to setup and use the
> validations.xml or
> am I going about this in the wrong way?
>
>
> <?xml version='1.0' encoding='windows-1252'?>
> <form-validation>
> <global>
>   <constant>
>       <constant-name>phoneFormatMask</constant-name>
>       <constant-value>^[0-9]{3}-[0-9]{4}$</constant-value>
>   </constant>
>   <constant>
>       <constant-name>areaCodeFormatMask</constant-name>
>       <constant-value>^[0-9]{3}$</constant-value>
>   </constant>
> </global>
> <formset>
>   <!-- Start of validation rules for each bean -->
>   <form name="contactBean">
>    <field property="firstName" depends="required" page="1">
>      <arg0 key="validation.error.firstname"/>
>     </field>
>     <field property="lastName" depends="required" page="1">
>      <arg0 key="validation.error.last"/>
>     </field>
>     <field property="email" depends="required, email" page="1">
>      <arg0 key="validation.error.email"/>
>     </field>
>     <field property="areaCode" depends="required, areaCodeMask" page="1">
>      <arg0 key="validation.error.areaCode"/>
>       <msg name="areaCodeMask" key="validation.error.areaCode.format"/>
>       <var>
>         <var-name>areaCodeMask</var-name>
>         <var-value>${areaCodeFormatMask}</var-value>
>       </var>
>     </field>
>     <field property="phoneNumber" depends="required, phoneMask" page="1">
>       <arg0 key="validation.error.phone"/>
>       <var>
>        <var-name>phoneMask</var-name>
>        <var-value>${phoneFormatMask}</var-value>
>       </var>
>     </field>
> ....
> </form>
> </formset>
> </form-validation>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.