Reputation: 1773
I have a 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.");
}
}
}
You can see that I have a errors property in StudentBean (List). i realized that variable name has a conflict with the errors where the bean error is stored. What i did was changed the closure to something like this
age nullable : false, validator : { val, obj, errorsValue->
if(val<10)
errorsValue.rejectValue("age", "student.age.notQualified.message", [val] as Object[], "Student not qualified.");
}
but I couldnt loop the errorsValue to get the error.
When I check what errors is this is what docs says:
The errors property on domain classes is an instance of the Spring Errors interface. The Errors interface provides methods to navigate the validation errors and also retrieve the original values. https://grails.github.io/grails-doc/latest/guide/validation.html
so this is the property of the domain class, probably declared but hidden. The question is can I change the errors property name to something else?
Upvotes: 0
Views: 93
Reputation: 24776
You can not change the validation errors property.
The reason for this comes down to the philosophy behind Grails. errors
exists on all Grails domain classes by convention. Much of what makes Grails powerful is not the configuration but rather the "convention over configuration". This ensures consistency between Grails projects and makes the entire framework simpler to learn and use.
Upvotes: 1