This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts conditional/dependent validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts conditional/dependent validation" Watch "Struts conditional/dependent validation" New topic

Struts conditional/dependent validation

Ken Pelletier
Ranch Hand

Joined: Aug 01, 2002
Posts: 54
Is it possible to create a validation rule (validation.xml) that will apply a set of other rules to a given form property depending on the value of another form property?

I'm using Struts 1.2.4, and am aware of (and using) validwhen for dependent validation where a rule is expressed in terms of another property's value and a boolean expression.

I want to make the application of certain rulesets conditional on the value of another property.

One example is an industry-specific credit card that has a different format from the standard CreditCardValidator's (which is the commons validator that Struts uses out of the box for credit card).

Given a 'type' property and a 'cardNumber' property, I'd want to apply the stock CreditCardValidator rules only when the type is not the known industry-specific type code, otherwise I want to apply a simple regexp mask.

Short of creating another CreditCardType-implementing class and wiring it into my own validator rule, can this sort of thing be done in the xml validation def?
It is sorta covered in the JavaRanch Style Guide.
subject: Struts conditional/dependent validation
Similar Threads
struts action form not working
Valid when
Issue when using shale commons validator with JSF
struts - using validwhen for password validation
Error handling in Struts