|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=TYPE) @Documented public @interface SessionScope
Annotation that is used to specify that an ActionBean should be instantiated and stored across requests in the Session scope. By default ActionBeans are instantiated per-request, populated, used and then discarded at the end of the request cycle. Using this annotation causes an ActionBean to live for multiple request cycles. It will be instantiated and put into session on the first request that references the ActionBean. A reference to the bean will also be placed into RequestScope for each request that references the bean, thereby allowing the rest of Stripes to treat it like any other ActionBean.
Since session scope ActionBeans are not generally encouraged by the author, very few allowances will be made in Stripes to accommodate session scope beans. This means that additional mechanisms to handle session scope beans do not exist. However, there are general mechanisms built in to Stripes that will allow you to overcome most if not all issues that arise from Session scoping ActionBeans.
One major issue is how to clear out values from an ActionBean before the next request cycle. It is suggested that this be done in the ActionBean.setContext() method, which is guaranteed to be invoked before any binding occurs. Note that this problem is two-fold. Firstly the browser does not submit values for checkboxes that are de-selected. Secondly Stripes does not invoke setters for parameters submitted in the request with values equal to the empty-string. You may choose to simply null out such fields in setContext() or use the available reference to the HttpServletRequest to find out if empty values were submitted for fields, and null out just those fields.
A second major issue is in using the validation service. The validation service validates what was submitted in the request. Therefore if a property is marked are required, is present in the session scope bean, but is not submitted by the user, it will generate a required field error. This may or may not be desired behaviour. If it is not, it is suggested that the ActionBean implement the ValidationErrorHandler interface to find out about the validation errors generated, and take action accordingly.
Lastly, an alternative to session scoping for wizard pattern/page-spanning forms that
ActionBean authors may wish to consider is the use of the
WizardFieldsTag
which will carry all the fields submitted
in the request into the next request by writing hidden form fields.
ValidationErrorHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |