Reputation: 1773
Im currently working on grails constraints. I have class that looks like this
@Validateable
class StudentBean{
def String name;
def String age;
def String address;
def List<ErrorBean> errors = [];
static constraints = {
age nullable : false, validator : { val, obj, errors->
if(val<10)
errors.rejectValue("age", "student.age.notQualified.message", [val] as Object[], "Student not qualified.");
}
}
}
Now, assuming I declared a lot of constraints and then I call student.validate()
How will I know if a specific property has an error? Example, I just want to know if "age" property has an error?
Upvotes: 1
Views: 257
Reputation: 4177
If you're sure that your object has errors by checking student.validate()
, you can use:
student.errors.getFieldError( "age" )
Remember that you can also validate only custom properties:
student.validate(["age"])
Upvotes: 3