commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Winterfeldt <dwinterfe...@yahoo.com>
Subject Re: [Commons-Validator] required validation type
Date Wed, 15 May 2002 15:51:34 GMT
You can create your own validators in the xml file. 
Just copy the required validator definition you are
using and have it point to your own method.  Then you
could have the validation always return true if the
field doesn't exist in the request object.


<validator name="conditionalRequired"
                
classname="org.apache.commons.validator.TestValidator"
                 method="validateConditionalRequired"
                
methodParams="java.lang.Object,org.apache.commons.validator.Field,javax.servlet.http.HttpServletRequest"/>

public boolean validateConditionalRequired(Object
bean, Field field, HttpServletRequest request) {

   if (request.getParameter(field.getProperty()) !=
null) {
      // check for required conditions
   } else {
      return true;
   }

}

David

--- Eric Beaumier <eb2_mailinglist@yahoo.ca> wrote:
> Hi, I post it again ...
> 
> 
> Actually the validateRequired use the generic method
> isBlankOrNull for consequence, if the INPUT text
> field
> is not in the <FORM> it prompt an error "is
> required".
> 
> Could we have another type (ex: "notblank") allowing
> 
> the validation only if present?  Because to avoid 
> recreation of the same <form> definition in
> validation.xml with the field or not ...
> 
> Because we reuse the <form> in validation.xml for 
> different JSP page ... treated the same fields name.
> 
> 
> Thanks.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
> 
> --
> To unsubscribe, e-mail:  
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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


Mime
View raw message