• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts2 conversion/validation problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 38
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic