You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2005/04/12 20:42:06 UTC

[Jakarta-commons Wiki] Update of "CommonsChainAndSpringFramework" by JoeGermuska

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:
http://wiki.apache.org/jakarta-commons/CommonsChainAndSpringFramework

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"?>
  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
  <beans>
@@ -73, +79 @@

  		</property>
       </bean>	
  </beans>
- 
+ }}}
  * Declare the Spring plugIn in your struts configuration file
- 
+ {{{
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
      <set-property property="contextConfigLocation"
                      value="/WEB-INF/applicationContext.xml"/>
  </plug-in>
- 
+ }}}
  * 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org