简体   繁体   中英

Groovy/Grails default error message

I'm trying to customize my errors mesages. Firstly, I want to get message key on output as an error, for example: package.Subpage.title.nullable.

To gain this goal I've deleted all message.properties bundles from my application but I still get something like this on output:

   Property [title] of class [class package.Subpage] cannot be blank

I've got properties of FieldError class to see if it's implemented there and I've noticed that this class has property:

   defaultMessage=Property [{0}] of class [{1}] cannot be blank 

Of course I know that there is a pattern for message key which looks like class.property.(blank or nullable or whatever constraint set) and I can override every message, but my main goal is to have full control on this how message key, message value and default message look like.

Is there any way to define default message and message key for errors in grails? 是否有任何方法可以为grails中的错误定义默认消息和消息密钥?

You can implement your own Spring MessageSource , then wire that into Grails:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM