Java Mailing List Archive

http://www.junlu.com/

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

Re: type validwhen validation

Niall Pemberton

2007-02-09

Replies:

On 2/9/07, Nathan Coast <nathan@(protected):
> thanks Niall,
>
> I've had a look at the examples and I'm not sure they demonstrate what I
> need. The examples all seem to be simple boolean expressions e.g.
>
>     <field property="address1" depends="validwhen">
>       <arg key="validWhenForm.address1" />
>       <var>
>        <var-name>test</var-name>
>        <var-value>( (*this* != null) or
>               ( (address2 == null) and
>               ( (city == null) and
>                 (zip == null) )))</var-value>
>       </var>
>     </field>
>
> I have a select (fieldB) that determines the type of fieldA. So the
> validation to operate on fieldA depends on the value of fieldB.
>
>     <field property="fieldA" depends="validwhen,required">
>       <arg key="form.fieldA" />
>       <var>
>        <var-name>test</var-name>
>        <var-value>
>     ((fieldB == 'java.lang.Integer') && validateInteger(fieldA))
>   || ((fieldB == 'java.lang.Float') && validateFloat(fieldA))
>   || ((fieldB == 'java.util.Date') && validateDate(fieldA))
> etc....
>       </var>
>     </field>

The above looks like JavaScript - because validwhen is server side
only. Either way validwhen doesn't cater for doing different types of
validation (e.g. integer, float etc) depending on a value.

> is this possible? I'm thinking not, so a custom validation method is
> probably what I need.

Looks like it

Niall

> cheers
> Nathan
>
>
> Niall Pemberton wrote:
> > On 2/9/07, Nathan Coast <nathan@(protected):
> >> Hi,
> >>
> >> I have two fields in a form. I believe the validwhen rule executes a
> >> specific rule (e.g. required) on field a based upon the value of field
> >> b. The situation I have is that I need to execute different validations
> >> on field a determined by the value of field b.
> >
> > Yes - theres a validwhen example page in the struts-examples webapp in
> > the binary distro (see the validation module).
> >
> >> Is this possible client side with the latest validator framework
> >> (1.3.1)? or will I have to implement this functionality in the validate
> >> method of the form (server side)?
> >
> > validwhen is server side only.
> >
> > Its also a custom Struts validator - not part of Commons Validator so
> > in that respect the version of Commons Validator is not relevant.
> >
> > Niall
> >
> >> cheers
> >> Nathan
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >> For additional commands, e-mail: user-help@(protected)
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

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

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