I have an Issue with form validation using an embedded class. The Main class and the embedded class both have an attribute with the same name. All attributes are mandatory. The JSP form contains both the inputs for the main object and the embedded one.
The error is manifests itself as:
If all fields are entered everything works correctly
If the duplicate attribute in the embedded object has errors (is blank) - the attribute in the main class also becomes blank and is hi lighted with errors. the controller clearly has the correct value before the view is rendered
Domain Class Example:
class Parent {
String name
String surname
Child child1 = new Child()
static embedded = ['child1']
static constraints = {
name(nullable: false, blank: false)
surname(nullable: false, blank: false)
}
}
class Child {
String surname
String name
static constraints = {
name(nullable: false, blank: false)
surname(nullable: false, blank: false)
}
}
View & controller attached.
is set on the errors. (see org.codehaus.groovy.grails.validation.AbstractConstraint)
The attached patch fixes this.
You have to change the parameters passed to the tags hasErrors and fieldValue:
the bean parameter has to be Parent and the field parameter uses a nested path, e.g. child1.name
Also the tags need to parse the nested path, the attached patch does this too.
Please take a look.