Struts2

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
(The Struts2/Resin-IoC capability requires Resin 3.1.5)
 
(The Struts2/Resin-IoC capability requires Resin 3.1.5)
  
[http://struts.apache.org/2.x Struts2] can work with Resin-IoC to enable all Struts actions with WebBeans-style injection.  Your MyAction class can use the WebBeans @In and @Named annotations to retrieve beans defined in the resin-web.xml.
+
[http://struts.apache.org/2.x Struts2] can work with [http://caucho.com/resin-3.1/doc/resin-ioc.xtp Resin-IoC] to enable all Struts actions with WebBeans-style injection.  Your MyAction class can use the WebBeans @In and @Named annotations to retrieve beans defined in the resin-web.xml.
  
 
Optionally, you can define action classes as beans in the resin-web.xml to enable extra configuration if necessary.
 
Optionally, you can define action classes as beans in the resin-web.xml to enable extra configuration if necessary.
Line 23: Line 23:
  
 
That's it.  No other configuration is required to enable your actions for Resin-IoC.
 
That's it.  No other configuration is required to enable your actions for Resin-IoC.
 +
 +
== ResinObjectFactory implementation ==
 +
 +
<code><pre>
 +
public class ResinObjectFactory extends ObjectFactory {
 +
  private WebBeansContainer _webBeans = WebBeansContainer.create();
 +
 +
  @Override
 +
  public Object buildBean(Class clazz, Map extraContext)
 +
  {
 +
    return _webBeans.getObject(clazz);
 +
  }
 +
}
 +
</pre></code>

Latest revision as of 08:59, 9 February 2008

(The Struts2/Resin-IoC capability requires Resin 3.1.5)

Struts2 can work with Resin-IoC to enable all Struts actions with WebBeans-style injection. Your MyAction class can use the WebBeans @In and @Named annotations to retrieve beans defined in the resin-web.xml.

Optionally, you can define action classes as beans in the resin-web.xml to enable extra configuration if necessary.

The MyAction might look like:

 package example;

 import javax.webbeans.*;
 
 public class MyAction {
   @Named("wiki") DataSource _database;

   ...
 }

To enable Resin-IoC with Struts, you'll need to copy the resin/ext/resin-support.jar to either WEB-INF/lib or resin/ext-webapp. And you'll need to create or modify WEB-INF/classes/struts.properties as follows:

 # Tell struts to ask Resin for new action instances
 struts.objectFactory = com.caucho.xwork2.ResinObjectFactory

That's it. No other configuration is required to enable your actions for Resin-IoC.

[edit] ResinObjectFactory implementation

public class ResinObjectFactory extends ObjectFactory {
   private WebBeansContainer _webBeans = WebBeansContainer.create();

  @Override
  public Object buildBean(Class clazz, Map extraContext)
  {
    return _webBeans.getObject(clazz);
  }
}
Personal tools