0

我有以下...

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)    
4

1 回答 1

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())
                }
            }
        }
    }
}
于 2014-08-18T15:42:11.667 回答