Woah, sorry, i messed up that subject line (missed the RE: ), so if you're looking for the original post, its: http://mail-archives.apache.org/mod_mbox/tapestry-users/200709.mbox/[EMAIL PROTECTED]
On 9/12/07, lasitha <[EMAIL PROTECTED]> wrote: > Marcus, you mentioned offline you'd gotten this to work by setting the > Loop component's 'volatile' parameter to true. I've scanned the > source and must admit i don't quite understand how the component is > designed to work when _not_ volatile. If anyone's had any success > updating state within a non-volatile loop, please chime in. > > I do have a couple of related suggestions: > > 1. If you don't use an encoder, tapestry will try to serialize the > whole list (forcing the contained type to implement Serializable). > This might be ok - particularly if you use a client storage strategy - > but i think its cleaner to use a primary key encoder and allow it to > look up the list values from your backend on every hit. This also > ensures you don't run the risk of having two sets of objects floating > around. > > I've modified your example to use an encoder and appended the code below. > > You might also want to check out the ToDoList example in the > tapestry-core test source: > https://svn.apache.org/repos/asf/tapestry/tapestry5/trunk/tapestry-core/src/test > Look for: org.apache.tapestry.integration.app1.pages.ToDoList.java and > the corresponding ToDoList.html > > (There's also a ToDoListVolatile variation, but its essentially your > solution with volatile="true"). > > 2. Perhaps a Grid component is a more natural (albeit heavier) fit for > this kind of scenario? It may not be worth it if your example doesn't > get any more complicated, but throw in some validation, add/delete use > cases and the simple list may not hold up. I haven't used a Grid > myself, but i hear good things :) > > Cheers, > lasitha > > public class TestList { > private DefaultPrimaryKeyEncoder<String, Value> encoder; > private Value value; // current loop variable > private ValueRepository valueRepository = new ValueRepository(); > // would be @Inject-ed instead > > public void onPrepare() { > encoder = new DefaultPrimaryKeyEncoder<String, Value>(); > for(Value value: valueRepository.retrieve()) { > encoder.add(value.getName(), value); > } > } > public void onSuccess() { > repository.update(encoder.getValues()); > } > public List<Value> getValues () { > return encoder.getValues(); > } > public PrimaryKeyEncoder getEncoder() { > return encoder; > } > public Value getValue () { > return this.value; > } > public void setValue (Value value) { > this.value = value; > } > > public static class Value { > private String name; > private String text; > private boolean used; > > public Value(String name, String text, boolean used) { > this.name = name; > this.text = text; > this.used = used; > } > public String getName () { > return this.name; > } > public void setName (String name) { > this.name = name; > } > public String getText () { > return this.text; > } > public void setText (String text) { > this.text = text; > } > public boolean isUsed () { > return this.used; > } > public void setUsed (boolean used) { > this.used = used; > } > } > > > public static class ValueRepository { > > private static List<Value> values = new ArrayList<Value>() {{ > add(new Value("first", "text one", false)); > add(new Value("second", "text two", false)); > add(new Value("third", "text three", false)); > }}; > public List<Value> retrieve() { > return values; > } > public void update(List<Value> values) { > // in this case, the Value instances in the static list > have already been modified in place > // if this were a DB backed repo, we might loop through > the values and persist 'em here > } > } > } > > > On Wed, 05 Sep 2007, Marcus Schmidke wrote: > > > > ... > > > > I'm trying to edit a list of values: > > ... > > > > The page is rendered perfectly. On Submit, the new values are passed > > into some Value objects. > > > > But: those Value objects are serialized/deserialized instances of the > > original Value objects. While the List still holds the original Value > > objects, only copies of them get modified. Result is that my program > > code (which works on the list) never sees the modified versions, and > > on re-rendering, the old values are displayed again. > > > > What am I doing wrong?? > > > > > > Marcus. > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
