Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change 
notification.
The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/RolloverScope

The comment on the change is:
Minor updates

------------------------------------------------------------------------------
  
  = Rollover Scope for Struts 1.x =
  
- Traditionally web applications have stored state information either in in the 
HTTP request or in the HTTP session. If request object is used, a common 
practice to preserve state between request is to save it into HTML FORM; in 
this case moving back and forward along page history changes the state. If 
session object is used, it may open a potential source of memory leak, because 
application has to explicitly remove user objects from session.
+ Traditionally web applications use to store state information either in in 
the HTTP request or in the HTTP session. 
  
- Caught between limitations of request object from the one hand and the 
necessity of laborious manual housekeeping of session object on another hand, 
developers rarely use redirection to split input and render tasks. This is 
unfortunate because Redirect-After-Post pattern is a simple and proven solution 
for creating user-friendly and error-resistant interfaces.
+ If request object is used, state is usually serialized to HTML page as part 
of HTML FORM. In this case moving back and forward along page history changes 
the state. Consider implementing an online store checkout service, using 
request object to store state. After a customer payed for goods, he can click 
Back button and pay again. To prevent this kind of error a token or similar 
facility should be used.
+ 
+ If session object is used to store state, it may open a potential source of 
memory leak, because application has to explicitly remove user objects from 
session. Also, opening several windows for same-type object like a product in a 
traditional CRUD application may not be possible, because session stores state 
corresponding only to one product.
+ 
+ Because of issues related to using session, many developers abstain from 
using it, and prefer fighting with double submit problems and POSTDATA messages 
instead. They rarely split input and render tasks into two actions; when they 
do, they use in-server forwarding instead of redirection, because request 
object does not survive between requests. This is unfortunate because 
Redirect-After-Post pattern is a simple and proven solution for creating 
user-friendly and error-resistant interfaces.
  
  Starting from Struts 1.4 it will be possible to store data related to a 
multi-request conversation in the Rollover Scope.
  
@@ -14, +18 @@

  
  == Rollover scope in a nutshell ==
  
- Physically, a rollover scope is a map stored within session scope. One 
session can have one or more associated rollover scopes. 
+ Physically, a rollover scope is a map stored within session scope. One 
session object can store several associated rollover scopes.
  
  Rollover scope can be used in the following ways:
-  * Directly from use code through methods of RolloverScope class. [not tested]
+  * Directly from application code by calling methods of RolloverScope class. 
[not tested]
-  * Indirectly through saveXXX() and loadXXX() methods of Action class. [not 
implemented yet]
-  * By specifying action form scope in an action mapping of struts-config.xml 
file. [implemented]
+  * By passing rollover scope to saveXXX() and loadXXX() methods of Action 
class. [not tested]
+  * By specifying rollover scope for an action form in struts-config.xml file. 
[implemented]
  
  A rollover scope can be configured for automatic garbage collection. Two 
techniques are possible:
-  * Setting scope lifetime when the scope is created.
-  * Specifying a scope as a storage for an action form that corresponds to a 
multi-request conversation like a wizard.
+  * Specifying removal strategy (by timeout or by request count) and a 
limiting value (number of requests or time to live) at scope creation time. 
Scope will be removed when its lifetime counter exceeds limiting value.
+  * Specifying a release property in action mapping; when action forwards to a 
release target, the rollover scope is destroyed.
  
  == Using rollover scope explicitly from application code ==
  
- To obtain an instance of a rollover scope use {{{RolloverScope.getInstance}}} 
static method. If the scope you are accessing does not exist and "create" flag 
is true, new scope will be created.
+ (Not all statements of this section are backed up by actual code)
  
- To store data in a scope or to read data from a scope use appropriate methods 
of Map interface. Rollover scope is just an enhanced Map.
+ To obtain an instance of a rollover scope use {{{RolloverScope.getInstance}}} 
static method. If the scope you are accessing does not exist and "create" flag 
is true, new scope will be created. When a rollover scope is accessed 
explicitly, its content is not copied to request scope.
  
- To remove rollover scope from the session object use 
{{{RolloverScope.remove}}} method.
+ To store data in a scope or to read data from a scope use appropriate methods 
of Map interface. Rollover scope is just an enhanced Map. If "writeThrough" 
flag was set at scope creation time, then all data written to the rollover 
scope is duplicated in the request object.
+ 
+ To remove rollover scope from the session object use 
{{{RolloverScope.remove}}} method. If "writeThrough" flag was set at scope 
creation time, rollover data is removed from request scope as well.
+ 
+ == Using saveXXX methods of Action class ==
+ 
+ TBD
  
  == Using rollover scope to store an action form ==
  
- In a Struts application a rollover scope can be used just as any other J2EE 
scope, including action mappings. To declare a rollover scope for an action 
form use scope="rollover" in action mapping definition. Below is an example of 
a standard redirect-after-post pattern: one mapping for submitting user data 
from browser, another mapping for rendering a web page. A rollover scope is 
used to store form bean in between requests. The input action inherits from 
!EventDispatchAction and is used as event processor. Render action uses 
login/logout state to render an appropriate view.
+ In a Struts application a rollover scope can be used in action mapping 
definition just as request and session scopes. To declare a rollover scope for 
an action form specify {{{scope="rollover"}}} in action mapping definition. 
Below is an example of a standard redirect-after-post pattern: one mapping for 
submitting user data from browser, another mapping for rendering a web page. A 
rollover scope is used to store form bean in between requests. The input action 
inherits from !EventDispatchAction and is used as event processor. Render 
action uses login/logout state to render an appropriate view.
  
  Events are defined in 'parameter' attribute (see !EventDispatchAction for 
details). Notice that 'scope' has 'rollover' value. A removal strategy of with 
lifetime of one request is defined for rollover scope - perfect for most 
redirect-after-post use cases. 
  

Reply via email to