PDA

View Full Version : [Complex Form] binding of nested models



Javaspritz
Mar 28th, 2012, 01:00 AM
Hi all,

for first sorry for my english.

I've a complex Form where I need to bind nested objects into the master model attribute.

I mean: I've a Form to handle a "Contract" data, in this Form I can add multiple "Contract conditions" and each "Condition" has multiple "Condition details".

So a "Contract" has a property with a collection of "conditions" and each "condition" has a a property with a collection of "details".

The tables relationship and corresponding hierarchy of java classes are corrects but I don't know how to bind nested objects into the "Contract" ModelAttribute.

I don't know ho to us PropertyEditors to handle this situation.

If I have an input form link this:


<input type="text" name="conditions[0].fromDate" />

Property Editor for "Condition" objects is not triggered.

If I write only:

<input type="text" name="conditions[0]" />
It works but I need to set each property of that condition.

I need to create N conditions:


<input type="text" name="conditions[0].fromDate" />
<input type="text" name="conditions[0].toDate" />
<input type="text" name="conditions[0].description" />

<input type="text" name="conditions[1].fromDate" />
<input type="text" name="conditions[1].toDate" />
<input type="text" name="conditions[1].description" />

....


How can I catch a "conditions[n].property" in POST data and bind it into the Model Attribute?

Thanks a lot.