commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Jakarta-commons Wiki] Update of "CommonsChainAndSpringFramework" by JoeGermuska
Date Tue, 12 Apr 2005 18:42:06 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by JoeGermuska:

The comment on the change is:
Mention CatalogFactory as another option; style comment about command lookup

- {{{Below are the steps of a possble solution for using commons-chain with Struts, having
the Catalog configured via Spring.
+ Below are the steps of a possible solution for using commons-chain with Struts, having the
Catalog configured via Spring.
- Write an implementation of org.apache.commons.chain.Catalog interface which must implement
also org.springframework.context.ApplicationContextAware in order to retrieve commands from
spring configuration file.
- Below is a possible implementation 
+ If you only need a single Catalog, you can write one which assumes that the name of any
command is the name of a Spring bean, and looks up the Command
+ using the Spring ApplicationContext.
+ If you need multiple catalogs, you would want an implementation of the CatalogFactory class
which can wire together beans from Spring.  This should be pretty simple, but no code is provided
here yet.
+ Below is a possible implementation of the single-Catalog solution.
+ {{{
  public class SpringCatalog implements Catalog,ApplicationContextAware {
  	 private ApplicationContext appContext;
@@ -40, +45 @@

+ }}}
  * Declare your Catalog class and commands in your spring configuration file (usually it
is applicationContext.xml). 
+ {{{
  <?xml version="1.0" encoding="UTF-8"?>
@@ -73, +79 @@

+ }}}
  * Declare the Spring plugIn in your struts configuration file
+ {{{
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
      <set-property property="contextConfigLocation"
+ }}}
  * Write an Action class servers as base to retrieve commands
+ {{{
  public class CommandAction extends ActionSupport {
      protected static String SUCCESS = "success";
@@ -93, +99 @@

                                   HttpServletResponse response)
              throws Exception {
          Catalog catalog = (Catalog) getWebApplicationContext().getBean("catalog");
+         // Marco uses the mapping's name, but I would suggest that using the path or the
parameter are more appropriate,
+         // or in Struts 1.3, you could use the mapping's command property directly. 
+         // The "name" property is used to identify a form bean associated with the action
mapping, and may not be 
+         // appropriately unique for your business logic.  -- JG
  	 String name = mapping.getName();
  	 System.out.println("Retrieving command for action"+ name);
          Command command = catalog.getCommand(name);

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message