0

我有一个命令对象

@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
} 

但它不起作用。

4

1 回答 1

0

像这样的东西应该工作......

@Validateable
class PropertyDetailsCommand implements Serializable {
    Boolean ownerOccupied
    String personalDescription

    static constraints = {
        personalDescription validator:{value, obj ->
            if(obj.ownerOccupied && !value) {
                return 'blank'
            }
        }
    }
}
于 2014-09-24T16:37:25.507 回答