struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Winterfeldt <dwinterfe...@yahoo.com>
Subject Re: Weirdness/possible bug in Validator dependencies
Date Mon, 15 Jul 2002 19:57:13 GMT
The Validator was designed to work this way so there
could different groupings of validation rules. 
Because some times it may not make sense to continue
with certain validations until the form is in a
certain state.  The depends attribute in the pluggable
validator definitions is what controls these
groupings.  So to have validation performed on
everything at the same time, the depends attribute can
be either zero length or removed.

<validator name="mask"
    
classname="org.apache.struts.util.StrutsValidator"
        method="validateMask"
  methodParams="java.lang.Object,
               
org.apache.commons.validator.ValidatorAction,
                org.apache.commons.validator.Field,
                org.apache.struts.action.ActionErrors,
                javax.servlet.http.HttpServletRequest"
       depends="required"
           msg="errors.invalid">


David

--- James Turner <turner@blackbear.com> wrote:
> Let's say I have two validations:
>     <field
>       property="gender"
>       depends="required">
>       <arg0 key="subscriberForm.gender.label"/>
>      </field>
>     <field
>       property="dateOfBirth"
>       depends="required,date">
>       <arg0 key="subscriberForm.dateOfBirth.label"/>
>      </field>
> 
> Now, on the form, I leave gender blank and put
> garbage in for dateOfBirth.
> 
> When the form validates, gender is given an error
> because it is blank, and 
> dateOfBirth is not flagged at all.
> 
> Why?
> 
> Because in
> org.apache.commons.validator.Validator.validate(), 
> hActionsRun 
> is defined outside of the main loop.  This
> means that if any field fails the "required" test,
> dateOfBirth will never 
> run the "date" check because the required
> dependency fails, even though it's for another
> field.
> 
> If you then put an entry in gender, required passes,
> and on the next form 
> submission, you finally get your error for
> dateOfBirth.
> 
> If hActionsRun were moved inside the loop, it would
> work 
> correctly.  However, it would mean that one field
> couldn't have a 
> dependency that was
> defined by another, which I think is OK, since
> that's not supposed to be 
> kosher as far as I can tell.  Should I submit that
> as a patch against commons?
> 
> James
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:struts-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-dev-help@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message