Thank you very much, that was exactly what I was looking for. I am new
to tapestry and it was not clear for me how loops are working, but now I
understand it.  :-)

Also many thanks to the other guys that replied.

@Marcus: Grid didn’t work for me, because I didn't have any Bean that I
could pass.

@Francois: Looks like a nice component and a generic solution for that
kind of problem. But I think it was bit overkill for me.

@Igor: FormInjector may work, if I always start with one input field.
But I also have to provide an edit form where already can be a set of
values. I am not sure how I could implement this using the FormInjector.

Regards,
Michael


Josh Canfield schrieb:
> Hey Michael,
> 
> I know a couple of guys have replied, but I think there is a much
> simpler answer to your problem.
> 
> drop the item property from your page and add getter/setters that
> update the your items list based on the index in the loop:
> 
> @Property
> private int _index;
> 
> public String getItem() {
>       if ( items.size() <= _index ) {
>               // what to do when the index is out of bounds?
>       }
>       return items.get(_index);
> }
>       
> public void setItem(String s) {
>       if ( items.size() <= _index ) {
>               // what to do when the index is out of bounds?
>       }
>       items.set(_index, s);
> }
> 
> 
> and update the loop div in your template to bind the index property:
> <div t:type="loop" t:source="items" t:value="item" t:index="index">
> 
> The way your page was written you were telling tapestry to update the
> item property for each value in the list, which it dutifully did. But,
> what you really wanted was it to put the items into your list.
> 
> Hope that helps,
> Josh
> 
> On Tue, Apr 15, 2008 at 6:51 AM, Michael Dukaczewski
> <[EMAIL PROTECTED]> wrote:
>> I am using Tapestry 5.0.11 and have a problem with a dynamic list of strings
>> in a form. What I am trying, is the following:
>>
>> In the Page.java:
>>
>> @Persist
>> private List<String> items;
>>
>> @Property
>> private String item;
>>
>> public List<String> getItems() {
>>        if (items == null) {
>>                items = new LinkedList<String>();
>>        }
>>        return items;
>> }
>>
>> public void onSelectedFromAdd() {
>>        getItems().add("");
>> }
>>
>> And in the Page.tml:
>>
>> <t:form>
>>        <div t:type="loop" t:source="items" t:value="item">
>>                <t:textfield value="item" />
>>        </div>
>>        <div><t:submit t:id="add" value="more"/></div>
>>        <div><t:submit t:id="save" value="save"/></div>
>> </t:form>
>>
>>
>> I have a list of values, the user has to enter. The number of values, that
>> have to be typed in, is dynamic, so the user has to extend the form.
>> The add button works, but the values are not saved. Can someone tell me,
>> that I am doing wrong?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to