Posts Tagged ‘i18n’

How to customize error messages for command objects in Grails

August 24, 2012

Basically, it works as it does for domain classes (see Grails documentation on validation).

However, command objects are often subclasses of controllers. Keep in mind that with subclasses it is *not* just like myCommandObject.myProperty.blank.
Instead, you have to write myParentClass$MyCommandObject.myProperty.blank. That’s it.

By the way: if you encounter problems with custom error messages not displayed, this is very easy to debug. Just create a breakpoint and inspect the command object, have a look at errors.errors[i].codes, it contains all message codes Grails will try for this specific error with index i