This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Struts2: use EmailValidator in my validate() method?
M Turner
Greenhorn
Joined: Dec 16, 2009
Posts: 25
posted
0
Can I still leverage the type validators in my validate() method if I'm not using an xml file? I need to override validate() for my form validation, but still want to leverage some of the type validators from the framework. Is there an example of how to use the type validators without the xml? In Struts 1x, I would have used GenericTypeValidator - do I have to add Commons Validation to my project on top of the XWorks Validation to get type validators?
I guess I don't see why you *couldn't* leverage the XWork validations manually, but I also don't understand why you wouldn't just use the annotations. I don't think I've ever used them on their own.
It's unclear to me why you'd want to run the validate() method before the XML--XML validation is for the easy stuff, like "does this field even exist" etc. Anything more complex, which is what should go in the validate() method, would depend on the XML validation anyway, at least in every use case I've ever had. You might be able to play with the order of the interceptors; off the top of my head I honestly don't remember what the default order is or which interceptor does which part of the work--you might have to poke around in the source a bit if nobody else chimes in. Worst case scenario would be a relatively minor tweak to an existing interceptor.
M Turner
Greenhorn
Joined: Dec 16, 2009
Posts: 25
posted
0
Thanks for your thoughts Dave. My mind also went to reordering interceptors but then I knew I was in too deep...
Here's what I'm really getting at... I need to have only one error message for 3 fields - but I want to also test for whitespace which is build into requiredstring.. however that is a FieldValidator. So I tried the following:
which doesn't work and gives an error in my logs:
com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn Got result of null when trying to get Boolean.
I guess my real question is.. is there a nice way to test for whitespce in OGNL?