PDA

View Full Version : Using propertyeditor with validator on Date field


opsb
Mar 16th, 2006, 05:11 AM
I'm using a the CustomDateEditor to bind to a Date field. If a user provides an incorrect format I'd like to redisplay the original value along with a custom message.

The CustomDateEditor throws an IllegalArgumentException which causes the error message 'Value is incorrect!'.

I can't use a validator to provide a custom message as the exception gets thrown before the validator is called. How do I do it?

kenevel
Mar 16th, 2006, 09:26 AM
Spring generates a list of error message codes that go something like

typeMismatch.formName.propertyName,
typeMismatch.formName.propertyClassName,
etc

With debugging switched on you should be able to see these in the logs. All you then need to do is map the most specific one for your needs (the most general is I think TypeMismatch.propertyClass) to your error message.

Mike