History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-2540
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Paul Fairless
Votes: 8
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
Grails

[hasErrors, fieldValue] - validation fails when domain has duplicate attribute name in embedded class

Created: 27/Feb/08 06:28 AM   Updated: 04/Jul/08 05:20 AM
Component/s: TagLib
Affects Version/s: 1.0.1
Fix Version/s: 1.0.4

Time Tracking:
Not Specified

File Attachments: 1. File create.gsp (3 kb)
2. Text File GRAILS2540.patch (3 kb)
3. File Parent.groovy (0.4 kb)
4. File ParentController.groovy (2 kb)

Environment: Windows XP, grails 1.0.1


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jens Lukowski - 04/Jul/08 05:20 AM
The problem is that grails creates the same error and binds it to the Parent bean regardless which nested path
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.