PDA

View Full Version : Trapping parse errors in the validator?


jonmor
Feb 7th, 2006, 01:03 PM
I have a CustomDateEditor registered via initBinder(), but what I can't work out (although I'm sure it must be obvious and I'm just having a stupidity day) is how, within my validator, I trap any exceptions the CustomDateEditor might throw in its attempts to parse the input. For example, when I submit a form containing an invalid date, this is what ends up in my errors object for display on the form the user ends back at:

'Failed to convert property value of type [java.lang.String] to required type [java.sql.Date] for property 'betDate'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "29/01/tt"'

Obviously what I want is to trap this error and display a more useful message but I must have missed how I do this.

robmonie
Feb 7th, 2006, 07:48 PM
You can create messages for the conversion exceptions such as:

typeMismatch.java.util.Date={0} must be a date.


There's some good discussion on this here: http://forum.springframework.org/showthread.php?t=13825&page=2&highlight=typeMismatch.java.util.Date

Also, the javadocs...
http://www.springframework.org/docs/api/org/springframework/validation/DefaultMessageCodesResolver.html

http://www.springframework.org/docs/api/org/springframework/validation/DataBinder.html

cheers,
rob

jonmor
Feb 8th, 2006, 04:35 AM
Great, that answers my question nicely! Thanks.