The mutable object, an instance of HashSet, has become the default value for the field and the selectedSet property is reset to it at the end of each request. What you should do:
private Set<String> selectedSet; void onPrepare() { selectedSet = new HashSet<String>(); }| Prepare is a form event that allows the containing page/component to initialize itself for either a form render, or a form submission. On Thu, Jul 9, 2009 at 6:46 AM, Alfie Kirkpatrick<alfie.kirkpatr...@ioko.com> wrote: > I have a page with a grid in a form and a checkbox per row in the grid. > The checkbox is bound to a property in the page which backs off to a > hash set, like so: > > > > // TODO: not sure why this works - should not be persisted between > requests! > > private HashSet<String> selectedSet=new HashSet<String>(); > > > > public boolean getCurrentSelected() { > > return selectedSet.contains(current.getContentId()); > > } > > > > public void setCurrentSelected(boolean value) { > > if ( value ) { > > selectedSet.add(current.getContentId()); > > } else { > > selectedSet.remove(current.getContentId()); > > } > > } > > > > In this case 'current' is the row in the grid and it works perfectly on > form submit, etc which I was pleasantly surprised about! > > > > What I'm confused about is that the selectedSet appears to be held > between page requests (which do not involve a submit of the form). I > would expect this value to be cleared out, or does that only happen for > properties/parameters that are annotated? Or is something else going on > here? > > > > Also, am I just lucky that I'm always getting the same page back from > the pool - would the above break for multiple users? > > > > Clearly I should set this to persist in session but am concerned that > unwary developers could use the pattern above and introduce subtle > application bugs without realising it. Shouldn't tapestry error or warn > about non-annotated private fields in a page class - is there ever a > case where it makes sense to use them? > > > > Thanks, Alfie. > > -- Howard M. Lewis Ship Creator of Apache Tapestry Director of Open Source Technology at Formos --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org