permaculture playing cards
The moose likes Struts and the fly likes Struts2 - Conditional validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 - Conditional validation" Watch "Struts2 - Conditional validation" New topic

Struts2 - Conditional validation

James Dutt

Joined: Apr 16, 2009
Posts: 9
I have tabs created using jquery in a struts2 form. At a given point of time, I will enter values for fields in any one of the tab and submit it. Rest of the tabs' fields will be blank. I have validation rule set for all the fields in all the tabs using action-validation.xml. So the validation is fired for all fields - as all the tabs& fields are in one <form>.

Stating this, Can I control the validation to only one tab and ignore other tab fields in action-validation.xml? We have something called depends="validwhen" in struts 1.x. Do we have something like that in struts2? the short-circuit is useful only to ignore rest of the validation set for a single field. correct me if i am wrong. Bottom line is, even though my form submits all the fields, I want my action-validation.xml to validate only the fields in active tab. Any thoughts?

Please let me know.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Expression validation can validate against any OGNL expression.

That said, it might be easier and/or more maintainable to do complicated validation in Java, possibly combined with XML- or annotation-based validation. Just keep a hidden value indicating which tab you're on.
I agree. Here's the link:
subject: Struts2 - Conditional validation
It's not a secret anymore!