permaculture playing cards
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
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?
I agree. Here's the link:
subject: Struts conditional/dependent validation
It's not a secret anymore!