struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niall Pemberton <niall.pember...@gmail.com>
Subject Re: How do i do this validation in struts using validWhen
Date Tue, 01 Nov 2005 14:22:48 GMT
On 11/1/05, Ashish Kulkarni <kulkarni_ash1312@yahoo.com> wrote:
> Hi
> Suppose i have entry text fields on a jsp, named ttype
> and comment,
> i want to add a validation saying that if ttype='2',
> then comment cannot be blank, if ttype='3' or any
> other value then comment can be blank,
>
> what i am trying is following
> <form name="ContractApprovalForm">
>  <field property="comment" depends="validWhen">
>        <arg0 key="errors.comment" />
>         <var>
>        <var-name>test</var-name>
> <var-value>(ttype==2) and (comment !=
> null)</var-value>
>        </var>
>  </field>
> </form>
> Will this work

No it won't - what you specify in the validwhen "test" variable is an
expression that if it results in "true" means validation passes -
otherwise it fails.

The condition you have means that the "comment" field will only be
valid when ttype is 2 and comment is not null. So if ttype is not 2 or
comment is not null validation will fail. To get it to work the way
you want your expression should say "comment is valid when either
ttype is not 2 OR comment is present" - that way when ttype is not 2
validation passes whatever tha value in comment, but when ttype is 2
then comment needs to be present.

The reply I posted to your quesiton yesterday showed an expression to
do exactly what you want (except it used 3 for ttype):

http://www.mail-archive.com/user%40struts.apache.org/msg36235.html

Niall

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


Mime
View raw message