Since Struts 1.3.x is unreleased, a better place for a thread like
this might be the DEV list.

On Apr 4, 2005 11:53 PM, Joe Germuska <[EMAIL PROTECTED]> wrote:
> Marco:
> 
> This is clumsy, but you could probably figure out a way to
> instantiate commands and chains as Spring managed beans and then,
> rather than looking them up in a catalog, you could look them up in
> the ApplicationContext.  If you did this, then it would be easy to
> set up your commands with references to other kinds of objects in the
> ApplicationContext, which I presume is one of the major goals.

I use Spring to create Commands, Chains, and Catalogs, using
Spring.Net and the Agility port of CoR. I did have to extend the API
though to add a property for adding a collection of Commands to a
Chain. The Commands themselves then become "SpringBeans".


> You could then extend the ExecuteCommand command, which is
> responsible for executing commands when the ActionConfig
> (ActionMapping) is appropriately configured.  You could override the
> "getCommand" method to have it look up the catalog and command using
> Spring instead of using the static CatalogFactory.getCatalog() method.
> 
> The only hitch here is getting a basic reference to the Spring
> ApplicationContext.  That this is even a hitch reveals a flaw in the
> commons-chain API (not that I'd really noticed before), but you could
> probably get away with extracting the context from the ServletContext
> with something like this:

If you are using Spring to instantiate Commands, then you can also
inject any dependencies a Command might have.

One technique is to create your own factory class that is
Spring-Aware, and expose a getObject method and whatever else you
might need. This factory can then be injected into any member that
might need to acquire another member. So the Commands could call a
getFactory().getObject(String) method to populate some other
SpringBean from a Context. (Thought, the Command doesn't know its a
SpringBean. All it sees is your Factory interface.)

- HTH, Ted.

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

Reply via email to