On 11/5/06, Adam Hardy <[EMAIL PROTECTED]> wrote:
I hope you don't mind if I jump in on this thread, after reading the
documentation refered to below.

What is the S2 convention for loading up objects for use by the JSPs or other
view logic?

It really isn't much different that Struts 1, except that the
ActionForm is combined with the Action, and all Actions are request
scope.

The simplest approach is to expose the object as a property on the
Action. The property can then fetch the object from the database or
session scope, as appropriate. If from a database, then the data
access logic might be encapsulated in a business facade, called by the
property. An application will often use a "support" object that
includes properties common to various Actions.



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.

-- HTH, Ted.
** http://husted.com/struts

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to