Rafal Markut wrote:
I have form with Offer informations (offer ID, date, offer
description etc.). I want add products to the offer. Amount of
products is dynamic, sometimes 1, sometimes 10. So I have button
which adds fields with product information. When I press button e.g.
5 times, then it generates in the form 5 times fields for product
information. Offer informations are in Offer-table. Product data are
in Product table - the tables are connected by foreign key, of
course.
If you have a logical Intake group with one or two fields that happen to
take multiple values sometimes, you might find it useful to use <field
name="MyField" multiValued="true">. Then, you can do something like this
in Velocity...
#set ($group = $intake.MyGroup.Default)
#set ($field = $group.MyField)
<input name="$field.Key" /> <input name="$field.Key" /> <input
name="$field.Key" />
...and something like this in the Java form handler:
Group group = intake.get("MyGroup", IntakeTool.DEFAULT_KEY);
Field field = group.get("MyField");
for (String value : (Collection<String>)field.getValue()) { /* do
something with the value */ }
---
If, on the other hand, you have several Intake fields that are repeated,
I might recommend a separate Intake group for those. For instance:
#* main part - only one per form *#
#set ($form = $intake.FormGroup.Default)
<input name="$form.Field1.Key" /><br />
#* sub parts - potentially several per form *#
#foreach ($i in [0 .. 3])
<hr />
#set ($subitem = $intake.SubitemGroup.setKey("_$i"))
<input name="$subitem.SubField1.Key" /><br />
#end
And in the Java handler:
Group form = intake.get("FormGroup", IntakeTool.DEFAULT_KEY);
Field field1 = form.get("Field1");
for (int i = 0; i < 3; ++i) {
Group subitem = intake.get("SubitemGroup", "_" + i);
Field subfield1 = subitem.get("SubField1");
}
The group keys are arbitrary; the only constraint is that the key used
in Velocity must match the key used in Java.
Oh, if you're using business-object mapping instead of accessing Intake
directly... I don't know much about that, so I hope you (or somebody
else) can figure that out. :)
Good luck!
Shane
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]