Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to validate this scenario using validation.xml

 
Prabu JayaPandian
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic