0

What is the best way to convert the developer-oriented validation error list you receive from calling validate() on a Grails domain object into user-oriented error messages?

Example:
Property [email] of class [class testproj.AuthUser] with value [x] is not a valid e-mail address

would rather have it read:
Email given is not a valid e-mail address

Is there anything built-in that already does this?

BuddyJoe
  • 69,735
  • 114
  • 291
  • 466

2 Answers2

6

the messages.properties files in grails-app/i18n

check out this documentation http://grails.org/doc/latest/guide/7.%20Validation.html

To get all the error codes, look here http://grails.org/doc/latest/ref/Constraints/email.html. Enable the quick nav on the right. At the bottom of every constraint is the properties key that you use to change the error message.

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
  • Any thoughts on what to try when this doesn't seem to work? Do you have to do something to specify message.properties or the fact you want English? I'm getting the same old full error messages. – BuddyJoe Jun 08 '11 at 20:52
  • Example: testproj.SecureUser.email.email=Email address is not valid – BuddyJoe Jun 08 '11 at 21:12
1

There is also a nice plugin called:

grails install-plugin i18n-templates

which can be found here http://www.grails.org/plugin/i18n-templates

e.g. you have a Domain class in 'org.example.User' and you want to specify the localization messages. Use the following command:

grails generate-i18n-messages org.example.User

This will generate a list of possible messages for you in the console. Copy and paste this output into your messages.properties for the English language and in every other message.properties for the language you want to have localizations.

Then you just have to edit these property-files in order to have your page localized. Eclipse/STS has a nice GUI, which makes localization of these property-files even faster.

Greetings,

Jan

Jan
  • 331
  • 1
  • 5