Dashboard > WebWork > ... > Cookbook > Using WebWork Components
  WebWork Log In View a printable version of the current page.  
  Using WebWork Components
Added by Bernard Choi, last edited by Philip Luppens on Feb 22, 2007  (view change) show comment
Labels: 
(None)

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.

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators