You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Whittemore, Leigh" <Le...@LibertyMutual.com> on 2003/04/14 19:55:43 UTC

Conditional Validator Rules

I have an application with forms which require some fields while allowing others as optional. I'd like to apply Struts validation rules (mainly from the default Struts Validator pluggable validator definitions) such as minlength, mask, etc. but on a conditional basis, in other words only when the field is, in fact, required. In digging down through the java classes and other puzzle pieces, it appears that most of these provided validation rules seem to be predicated on pre-running a "required" validation. It appears that a few may pass validation when sent a NULL field value but my forms always use initialized empty strings and would need to follow validation rules on existing field values during a "modify" transaction anyway.

Short of extending the base FieldChecks class (which I have done successfully to create conditional "if" classes, e.g. minlengthIf, maskIf, which pass validation when they are sent an empty string), am I missing some fundamental piece of Struts validation? Does anyone share my desire for validation classes that are only conditional on a field being required, instead of being only applicable to required fields? 

Leigh.Whittemore@LibertyMutual.com


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org