You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Rafal Markut <ra...@mediawave.de> on 2006/03/30 17:38:55 UTC
Intake - multiple Data objects and "dynamic" forms
Hello,
I use turbine 2.3.2 with torque 3.1.1.
I use intake to valid my forms.
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.
Does anyone know, how could I create such form with intake ?
with best regards,
Rafal
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Intake - multiple Data objects and "dynamic" forms
Posted by Rafal Markut <ra...@mediawave.de>.
Hello,
works perfectly, thank you
with best regards,
Rafal
----- Original Message -----
From: "Shane Beasley" <sb...@acm.org>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Friday, March 31, 2006 9:34 AM
Subject: Re: Intake - multiple Data objects and "dynamic" forms
> 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: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Intake - multiple Data objects and "dynamic" forms
Posted by Shane Beasley <sb...@acm.org>.
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: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org