Well it's because you are using strings directly. Here's what the
equivalent of what is going on in JAVA:

List<String> names  = NAMES;

for( String name : names ){
name = " NEW VALUE FROM INPUT FIELD";
// but strings are immutable so name has a new string reference and
does not modify
// the one that is part of the list.
}

What happens is your new name is stored only in the "name" property
and never makes it back to your list.... try printing out getName()
and you will see that it is probably set to your last name on the
list.....







On 1/10/07, Jim Downing <[EMAIL PROTECTED]> wrote:
Hi Daniel,

thanks for the help!

Daniel Tabuenca wrote:
> The Chart example the plotValues property is persisted:
>
> <page-specification
> class="org.apache.tapestry.workbench.chart.ChartPage">
>
>  <property name="plotValues" persist="session"/>
>
> .......
>
>
> I am assuming you are not persisting since from your logs:
>
> 9627410 [btpool0-3] INFO  com.example.pages.Home  - Begin render.
> Rewind? true
> 9627411 [btpool0-3] INFO  com.example.pages.Home  - Initializing names
> list

It's true, I wasn't persisting them. To be ultra-simplistic I've done
this by storing them back in a static field: -

Home.java:
...
    public static List<String> NAMES = new ArrayList<String>();
    public void pageBeginRender(PageEvent event) {
        LOG.info("Begin render. Rewind? " +
getRequestCycle().isRewinding() +". Names: "+ getNames());
        LOG.info("Initializing names list to "+ NAMES);
        setNames(NAMES);
    }

    public void submit() {
        LOG.info("Submitted. List is: " + getNames());
        NAMES = getNames();
    }

    public void add() {
        LOG.info("Adding a blank name to " + getNames());
        List<String> nms = getNames();
        nms.add("");
        setNames(nms);
    }
...


Unfortunately that doesn't seem to be at the heart of the problem - the
list now grows as desired when the 'add' listener is called, but the
values in the list aren't changed. It looks like the form values aren't
correctly set after the rewind, e.g. in the log excerpt below I'd be
expecting to see the (non-blank) form values in the message at the
highlighted point: -

 INFO  com.example.pages.Home  - Begin render. Rewind? true.  Names: null
 INFO  com.example.pages.Home  - Initializing names list to [, , ]
--> INFO  com.example.pages.Home  - Submitted. List is: [, , ] <--
 INFO  com.example.pages.Home  - Begin render. Rewind? false. Names: [, , ]
 INFO  com.example.pages.Home  - Initializing names list to [, , ]

Eventually I'm going to be saving the values in RDF - the values won't
have a persistent key, they're just literal values. I'm also keen to
avoid using any session persistence but will do if it's necessary. Can
tapestry deal with simple values that don't have identity in this way?

Thanks,

jim



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