[英]how to set custom error message for constraint violation of a grails domain object?
首先,域定义如下:
package com.abc.def
class EventDonation implements Serializable{
String title
String body
BigDecimal customDonationMin
BigDecimal customDonationMax
static constraints = {
title blank: false, nullable: false
body blank: false, nullable: false
customDonationMin min: BigDecimal.ZERO
}
}
视图页面中呈现错误的部分如下:
<g:hasErrors bean="${donation}">
<g:eachError var="error" bean="${donation}">
<li><g:message error="${error}"/></li>
</g:eachError>
</g:hasErrors>
最后,在message.properties
,添加的行如下:
com.abc.def.eventDonation.customDonationMin.min = Minimum limit cannot be less than 0
但是显示的错误是:
customDonationMin in class com.abc.def.EventDonation with value -10 is less than minimum value 0
您知道未显示自定义错误消息的原因吗?
原来我使用了错误的消息代码。 这是min属性的消息代码。
className.propertyName.min.notmet
参考: http : //grails.github.io/grails-doc/2.2.1/ref/Constraints/min.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.