You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ashish Kulkarni <ku...@yahoo.com> on 2005/11/01 15:10:22 UTC
How do i do this validation in struts using validWhen
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
Ashish
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How do i do this validation in struts using validWhen
Posted by Niall Pemberton <ni...@gmail.com>.
On 11/1/05, Ashish Kulkarni <ku...@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