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.

Reply via email to