 | As of WebWork 2.2, Spring is the preferred IoC container |
.
A simple example of using WebWork components is available in the webwork-example.war that comes with the WebWork 2.0 Beta 1 distribution. You can download the distribution from https://webwork.dev.java.net/servlets/ProjectDocumentList
.
Components are defined _/WEB-INF/classes/components.xml_.
The example consists of one component, which is defined by
<component>
<scope>session</scope>
<class>com.opensymphony.webwork.example.counter.Counter</class>
<enabler>com.opensymphony.webwork.example.counter.CounterAware</enabler>
</component>
com.opensymphony.webwork.example.counter.Counter is just a POJO.
com.opensymphony.webwork.example.counter.CounterAware is an interface which your *Action classes have to implement.
public interface CounterAware {
public void setCounter(Counter counter);
}
Additionally, you need to tag your actions with the intercepter, for example,
<action name="SimpleCounter" class="com.opensymphony.webwork.example.counter.SimpleCounter">
<result name="success" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<interceptor-ref name="defaultComponentStack"/>
</action>
WebWork will call the interface and set the Counter bean . The Counter bean would then be subsequently be available to be used by your *Action classes.