王子1986
王子1986

Reputation: 3609

Grails customised message not working

Github source code https://github.com/grails-samples/grails-petclinic

Customised message has been specified, unfortunately it doesn't work.

owner.firstName.blank=You must specify a first name

It shows error message "Property [firstName] of class [class org.grails.samples.Owner] cannot be null" instead of "You must specify a first name".

I have found the same issue in this screencast http://grails.org/screencast/22

Upvotes: 0

Views: 47

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

The issue you are running into is that you aren't customizing the correct message code. If you read closely you will see it's violating the nullable constraint not the blank constraint.

You should use:

owner.firstName.nullable=You must specify a first name

This may be confusing because in recent versions of Grails the default behavior for handling blank values for Strings was changed to use null instead of blank. There is a configuration option available to control this in Config.groovy if you wish to change back to the old behavior.

Upvotes: 2

Related Questions