Ted Husted on 05/11/06 21:27, wrote:
On 11/5/06, Adam Hardy <[EMAIL PROTECTED]> wrote:
Imagine a common-place user story where the user sees a list of items, and
can choose one item, go to the 'edit item' page, submit changes, and be
returned to the item list.
On the edit submit, my action processes the edit and does a save, and does
a Post-Redirect-Get back to the list.
Where do I put the logic fetching the list again? Obviously I don't want it
in the edit action. Do I put it in an action of its own, or do I put it in
an interceptor or even a PreResultListener?
Oh, in the normal course, I don't think anything so exotic would be needed.
:)
If we are fetching the list from a database, I'd put the actual logic in a
business facade. A good approach is to use Spring to instantiate the business
facade and then inject the business object into the Action. Struts 2 can
"autowire" Action properties from the Spring configuration. If you give the
Spring bean and the Action property the same name and type, the framework
will take care of the result.
* http://jroller.com/page/TedHusted?entry=struts_2_spring_love_fest
The list can be represented as a property on a base "support" Action that
other Action classes extend. All any Action needs to do is call the property,
and, behind the scenese, the property invokes the business facade. The
business facade itself can be autowired from Spring, so the Action just needs
to do is get the property name right!
If retrieving the list requires a key, a common approach is to create a
profile object that is stored in the session and can be retrieved as a
property on the base support Action.
You've made 75% of the code from my baseAction redundant! Come to think of it, I
suspect the remaining 25% can be farmed out into interceptors and that's the
whole lot.
The profile object / action interaction sounds interesting too. Can the
mechanism be mapped against tokens to identify the calling request in an app
allowing multiple windows?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]