aspose file tools*
The moose likes Struts and the fly likes how to validate this scenario using validation.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to validate this scenario using validation.xml" Watch "how to validate this scenario using validation.xml" New topic
Author

how to validate this scenario using validation.xml

Prabu JayaPandian
Greenhorn

Joined: Aug 04, 2008
Posts: 8
Please help me out in doing validation for the following scenario using Validation.xml

I have a drop down With 3 state values(ex: Kentucky,Michigan) and
a textbox which will accept the claim# for the state selected.

conditions.
1. Both state dropdown and claim# can be null.
2. A value is selected from State dropdown but no values can be entered for claim#.
3. Claim# format for each of the state selected are different(for ex Kentucky takes a String of length 8 or 9, MI takes a String of length 5).

I tried both requiredif and validWhen constructs in validation.xml but its not satisfying all sceanrios.


Please help me out with the validation.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd do it in Java: anything more complex than a single condition or a very simple two-state condition isn't worth trying to write in XML.
Prabu JayaPandian
Greenhorn

Joined: Aug 04, 2008
Posts: 8
Yeah.. Even i would like to do it that way..

But you got some crazy Team Leads and PMs out there..

SO please help me out if you have a solution
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, seriously: the limitations of validWhen makes this difficult and/or impossible. Combine the two forms of validation.

The other best option is to write and register a custom validator: this keeps the logic in Java code, where it belongs, and it more easily testable, but allows the configuration to still be entire in XML.

I won't help you with the validWhen expression--it would be too difficult to set up a way to test it, it's too finicky because of the way it was built, and substantially better options exist. Consider going the custom validator route--it's easy, and makes it look like the validation is entirely in XML, even though the tricky bits are somewhere else (where they're manageable).
 
Don't get me started about those stupid light bulbs.
 
subject: how to validate this scenario using validation.xml