You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Eric Beaumier <eb...@yahoo.ca> on 2002/05/14 01:54:32 UTC

[Commons-Validator] required validation type

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Commons-Validator] required validation type

Posted by David Winterfeldt <dw...@yahoo.com>.
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 <eb...@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:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


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

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