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]
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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

Reply via email to