13

I have a Person object with a lastName field. The lastName field cannot be blank. When the user submits a form blank value in the lastName field, the error message that the user sees is:

Property [lastName] of class [com.example.Person] cannot be blank

This error message is lame. I want to customize it to something more user friendly, like "The Last Name field cannot be blank"

How do I do that?

Spike Williams
  • 35,795
  • 13
  • 48
  • 60

2 Answers2

22

See Chapter 7 of the docs: http://grails.org/doc/latest/

You would change grails-app/i18n/messages.properties and add

person.lastName.blank=The Last Name field cannot be blank
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • Thanks. I'd spent a lot of time trying to track that one down - somehow I'd missed it on that page. – Spike Williams Feb 07 '11 at 15:50
  • There's also information in each constraint page about what property name it uses - those are in the left frame in the Constraints section. E.g. the creditCard constraint uses 'className.propertyName.creditCard.invalid' - see http://grails.org/doc/latest/ref/Constraints/creditCard.html for a direct link. – Burt Beckwith Feb 07 '11 at 19:46
  • 1
    it just don't work for me. It seems like grails version different cause this issue. – 王子1986 May 31 '15 at 00:45
  • 1
    Same here with Grails 2.5.0. I can't override messages from my plugin. – Ben Jul 17 '15 at 01:47
  • I'm also seeing this issue with Grails 2.5.0 - can't over-ride messages from plugin – Cookalino Jun 14 '16 at 13:53
  • Re: different grails version - Try searching for "Validation and Internationalization" in grails doc for your version. – sf_jeff Dec 06 '21 at 15:59
1

In Grails 3 you need to change in grails-app/i18n/messages.properties:

default.blank.message=The {0} field cannot be blank