You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by James Turner <tu...@blackbear.com> on 2002/10/23 10:15:19 UTC

Re: Validator and required dependency

Rob Leland <rl...@apache.org>  wrote:

 >Thanks for your experimentation, I had suspected something like this. In 
July patches were applied to the
 >Validator that changes its behavior. Specifically it no longer ignored 
blank fields. I was waiting till this weekend
 >when I get a solid block of time, so I could analyze the intent and 
purpose of these rules.

Here's the history of this:

In bygone eons (this summer), the Commons Validator had a lot of (to me) 
strange quirks.  For example, if you had the following:

name: depends=required
e-mail: depends=required, email

And you gave it a form that had an invalid e-Mail and a blank name field, 
you'd only get one error (for the blank name), because if a field had two 
dependencies, and the dependency had failed on ANY field, the second one 
wouldn't be ignored.

Well, many moons later, I've totally refactored the guts of Commons 
Validator, and a number of things have changed.  A vote was taken on the 
specific issue of how depends should work, and it was overwhelmingly agreed 
to that a depends= rule applies individually for a field.  And that's the 
way it works now.

 >I believe James Turner asked a similar question back in July and Dave 
replied that 'depends' determines if the
 >field is evaluated individually, or all together with the form as a 
whole. Like I said I will take a better look at it this
 >weekend. I am still new at using the Validator so right now what I say 
needs to be 'taken with a grain of salt',
 >evaluated by considering my experience.

Most people I've talked to (and on this list) seem to think that if you 
want a "required" dependency, you should place it explicitly on the list 
for the field.  By placing it on the rules in validation-rules.xml, it (for 
example) becomes impossible to do an optional e-Mail address field, without 
going in an removing the depends=required from the email rule in the 
supplied file.

I hope this clears things up a bit,
james



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>