This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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!
 
jQuery in Action, 2nd edition
 
subject: Struts2 conversion/validation problem
 
Similar Threads
Struts 2 + validate int value.
Struts 2 Validation
short-circuiting validations
Adding more than one validation to form field
short-circuit attribute not working in validation file