File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts2 conversion/validation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 conversion/validation problem" Watch "Struts2 conversion/validation problem" New topic
Author

Struts2 conversion/validation problem

M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
My model object has an XMLGregorianCalendar for a birthDate attribute. So I have created a custom converter which takes the string and converts it. Birthdate is also a required field.

My converter is global - I have it listed in the xworks-conversion.properties file

What's happening is that if the user types in a string which is not parseable by the MM/dd/yyyy pattern, the conversion error is thrown (great np there) HOWEVER the "required" validation error is thrown ALSO, so the screen shows up with the invalid message and the required message PLUS the birthDate field is blank.

I thought that ValidationAware was supposed to retain the user's original value? Also, I understand that the model object will not have a populated birthDate because the conversion failed, but is there a way to short-circuit the "required" validation if a conversion error occurs.

P.S I tried adding the following to the action-validation.xml file - in order to save the user's original entry :



However, the value isn't repopulated and now the "invalid" error is shown twice. I also tried adding "short-circuit="true" to the field-validator, but it didn't short-circuit the "required" logic.

Thanks
Mahendr Shinde
Ranch Hand

Joined: Sep 03, 2011
Posts: 38

Hi
Your problem might be because of "ConversionError" Interceptor who raises an Exception and automatically adds "Conversion" error to your field.
Plus, you have got your own "conversion" field validation. Your another problem is that, You have to "short-circuit" your first "required" validator.


There is still lot to learn!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 conversion/validation problem