0
首先如下:如何爲約束違反grails域對象設置自定義錯誤消息?所有的域定義的
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
您知道自定義錯誤消息未顯示的原因嗎?