3

New Problem:

I register / bind my custom property editor and get an java.lang.IllegalArgumentException - as expected. The problem: I do not know how to create a custom error message if binding fails.

Any idea? THX!

@InitBinder( { "playerCreationBean" } )
protected void initBinder( final WebDataBinder binder )
{
   binder.registerCustomEditor(Date.class, new DatePropertyEditor());    
}
axtavt
  • 239,438
  • 41
  • 511
  • 482
eventhorizon
  • 3,579
  • 3
  • 17
  • 9
  • See http://stackoverflow.com/questions/3270316/customize-spring-error-message/3270556#3270556. `IllegalArgumentException` throws from a custom property editor produces a `typeMismatch` message code. – axtavt Aug 24 '10 at 20:44

1 Answers1

1

axtavt is right. If you have a message bundle in your application (ie, messages.properties in your classpath, being used by a MessageSource implementation) spring can automatically use the friendly message in the bundle. The message 'typeMismatch' is just one of a number of default messages that are used by the binding framework, depending on the name of the object being bound as well as the property being bound to. You can use a debugger to inspect the errors instances after binding and find which messages are created by default when a binding exception occurs. I've found that the Spring Documentation is a bit lacking when it comes to the default message names that are generated.

Alex Marshall
  • 10,162
  • 15
  • 72
  • 117