我有一个命令对象
@Validateable
class PropertyDetailsCommand implements Serializable {
Boolean ownerOccupied
String personalDescription
static constraints = {
personalDescription validator:{value, obj, errs->
if(obj.ownerOccupied==true)
{
if(!value)
errs.rejectValue('personalDescription','propertyDetailsCommand.personalDescription.blank')
}
}
}
}
我在发表声明时发现了
if(obj.ownerOccupied==true)
存在,验证不起作用。
我尝试添加
static mapping={
ownerOccupied lazy:false
}
但它不起作用。
答案 0 :(得分:0)
这样的事情应该有用......
@Validateable
class PropertyDetailsCommand implements Serializable {
Boolean ownerOccupied
String personalDescription
static constraints = {
personalDescription validator:{value, obj ->
if(obj.ownerOccupied && !value) {
return 'blank'
}
}
}
}