Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts conditional/dependent validation

Ken Pelletier
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic