How to customize error messages for command objects in Grails

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

Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: