File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes doubt in using validwhen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "doubt in using validwhen" Watch "doubt in using validwhen" New topic

doubt in using validwhen

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
i want to validate the input fields based on a certain condition.

My validation.xml goes like this,

<form name="logonForm" >
<field property="username" depends="validwhen,required" >
<arg key="logonForm.username"/>
<var-value> (page == 9) </var-value>

<field property="password" depends="validwhen,required,mask" >
<arg key="logonForm.password"/>
<var-value> (page == 9) </var-value>



if the first condition fails(validwhen), the second shouldn't happen. But in my case despite of passing value zero for page, i get my 2nd validation executed.

please tell me where i am making mistake

when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
ValidWhen is only available in Struts Version 1.2 and above. You had mentioned in another thread that you're using Struts 1.1, so unless you've upgraded, the validWhen rule isn't going to work at all.

Secondly, I don't believe that your statement:
if the first condition fails(validwhen), the second shouldn't happen.

is necessarily true. I've looked through the documentation and haven't found anything that says one way or the other. My understanding is that a required validation rule will apply no matter what, regardless of its position in the list of validation rules. As I said, though, I haven't found statements to prove or disprove this in the documentation. If your statement is based on something you read in the documentation, please give us the link.
[ September 07, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: doubt in using validwhen
It's not a secret anymore!