Grails 自定义消息不起作用
Grails customised message not working
Github源代码https://github.com/grails-samples/grails-petclinic
已指定自定义消息,遗憾的是它不起作用。
owner.firstName.blank=您必须指定名字
它显示错误消息 "Property [firstName] of class [class org.grails.samples.Owner] cannot be null" 而不是 "You must specify a first name"。
我在这个截屏视频中发现了同样的问题http://grails.org/screencast/22
您 运行 遇到的问题是您没有自定义正确的消息代码。如果你仔细阅读,你会发现它违反了 nullable
约束而不是 blank
约束。
你应该使用:
owner.firstName.nullable=You must specify a first name
这可能会造成混淆,因为在最新版本的 Grails 中,处理 String
的空白值的默认行为已更改为使用 null
而不是空白。如果您想改回旧行为,Config.groovy
中有一个配置选项可用于控制此行为。
Github源代码https://github.com/grails-samples/grails-petclinic
已指定自定义消息,遗憾的是它不起作用。
owner.firstName.blank=您必须指定名字
它显示错误消息 "Property [firstName] of class [class org.grails.samples.Owner] cannot be null" 而不是 "You must specify a first name"。
我在这个截屏视频中发现了同样的问题http://grails.org/screencast/22
您 运行 遇到的问题是您没有自定义正确的消息代码。如果你仔细阅读,你会发现它违反了 nullable
约束而不是 blank
约束。
你应该使用:
owner.firstName.nullable=You must specify a first name
这可能会造成混淆,因为在最新版本的 Grails 中,处理 String
的空白值的默认行为已更改为使用 null
而不是空白。如果您想改回旧行为,Config.groovy
中有一个配置选项可用于控制此行为。