如何从父命令传播到grails中的子命令

时间:2014-06-20 19:35:18

标签: grails spring-validator

我有以下......

static constraints = {
  items nullable: true , validator: { val, obj ->
      if(val){
          for(int i = 0; i < val.size(); i++){
              BundleDefinitionCommand bdc = val[i]
              def errors = []
              val.each{
                  if(!bdc.validate()){
                      obj.errors.addAllErrors(bdc.errors.getAllErrors())
                  }
              }
              String test = "test"
          }
      }
  }
}

但是当我运行验证器时,我得到了......

No signature of method: grails.validation.ValidationErrors.addAllErrors() is applicable for argument types: (java.util.Collections$UnmodifiableList) values:....

我也试过......

obj.errors.addAllErrors(bdc.errors)    

1 个答案:

答案 0 :(得分:0)

我相信您应该将验证者签名更改为

validator: { val, obj, errors ->

并使用第三个参数:

errors.addAllErrors(bdc.errors.getAllErrors())

另外,抓住临时errors数组和String test

items nullable: true , validator: { val, obj, errors ->
    if(val){
        for(int i = 0; i < val.size(); i++){
            BundleDefinitionCommand bdc = val[i]
            val.each{
                if(!bdc.validate()){
                    errors.addAllErrors(bdc.errors.getAllErrors())
                }
            }
        }
    }
}