我想在自定义验证器中使用标准验证器。
我只想确保model_type.has_range_options
为false时,人口和产品字段组合才是唯一的。我尝试了以下方法,但无法正常工作:
static constraints = {
client validator: {val, obj, errors ->
if (!obj.model_type?.has_range_options?.booleanValue()) {
unique: ['population', 'product']
}
}
}
还有什么我可以尝试的吗?
最佳答案
我最后写了自己的独特验证:
static constraints = {
client validator: {val, obj, errors ->
if (this.findByPopulationAndClient(obj.population, obj.client) && !obj.model_type?.has_range_options?.booleanValue()) {
errors.rejectValue('client', 'unique', "Population and Client must be unique")
}
}
关于grails - 在自定义验证器中使用标准验证器进行Grails验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33618842/