简体   繁体   中英

Grails default error message text field name override?

In Grails we have default messages - this is great except where my field name is not what I would like. For example I have a property name such as propertyName and the message comes out: "propertyName is required" What I would like is "property name is required"

In other words can I override what Grails uses for arg[0]?

tia, Claude

If you consider such example:

class Foo {

  String propertyName

  static constraints = {
    propertyName blank: false
  }

}

if you provide such key in your messages.properties(message bundle file):

foo.propertyName.blank=property name is required - you will get what you want. Read the docs - default messages for constraints are explained and also how you can provide your own error codes. This is more flexible than providing own parameters for already embedded messages. If you tneed to, you can still embed arguments.

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