So it seems like directly manipulating the session is the defacto way to store cross-request objects in WW2 (and every other paradigm?) [see my previous post]. (Thanks for the advice, Jason. It’s active community involvement like this that makes projects such as yours and many other so successful). This got me thinking that the default scopes provided by the J2EE spec are pretty limiting, and that a good framework should provide a way to define intermediate scopes. Specific to WebWork 2, it seems like what needs to be defined is a lifespan of the various properties of the action. In my case I wanted the user property to span several actions. How about having property scopes defined in the xwork.xml like so:
<action ...> <property name="user" scope="session" /> ...
This allows the scope of each property to be defined outside the actual action without the need for directly manipulating session maps etc…. However, it is not as flexible as to allow the lifespan or scope to be set to a finite number or types of actions. What we need is a kind of a scope in between a request and a session. How about being able to define an action sequence as a scope in xwork.xml?
<scopes>
<scope type="actionSequence" name="userSequence">
<action-ref name="getUserAction" />
<action-ref name="saveUserAction" />
</scope>
</scopes>
Then scoping your action properties like so:
<action name="getUserAction" ...> <property name="user" scope-ref="userSequence" /> ... </action> <action name="saveUserAction" ...> <property name="user" scope-ref="userSequence" /> ... </action>
When the two requests occur in sequence or are chained, the user property of each action will be assured to be the same object. This would allow the flexibility of defining object lifespans beyond the limited request/session/application scopes that are now provided.
You could even go one step further and allow regular expressions when defining the action-ref attribute of each scope, so that all actions of a certain family can be grouped:
<scopes>
<scope type="actionSequence" name="userSequence">
<action-ref name="*UserAction" />
</scope>
</scopes>
Just seems like a way to tightly define specific property lifespans within the context of the application flow… Comments are welcome.
