Print
NanoWar WebWork

Overview

The NanoWar WebWork integration kit allows you to write WebWork/WebWork2 actions that are PicoContainer components. In other words, they can benefit from Dependency Injection.

Example

WebWork actions often integrate with business logic and/or persistence logic. In a non-Dependency Injection environment, the actions tend to be tightly coupled to the business logic and persistence layer tiers, and therefore hard to test in isolation.

NanoWar WebWork lets you use Dependency Injection.

public class CheeseAction extends ActionSupport {
    private final CheeseDao dao;

    public CheeseAction(CheeseDao dao) {
        this.dao = dao;
    }
}

The particularly nice thing about this is that it allows you to test the Action in isolation (by passing in a mock CheeseDao). And when you deploy the WebWork application, you can have NanoContainer provide the real CheeseDao (that possibly does some fancy Hibernate stuff or other).

WebWork Specific Configuration

First, follow the instructions for NanoWar

WebWork 1.x Configuration

Use the PicoServletDispatcher instead of the standard WebWork one. In web.xml:

<servlet>
    <servlet-name>WebWork</servlet-name>
    <servlet-class>org.nanocontainer.nanowar.webwork.PicoWebWork1ServletDispatcher</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

WebWork 2.0 Configuration

Use the PicoServletDispatcher instead of the standard WebWork 2 one. In web.xml:

<servlet>
    <servlet-name>WebWork</servlet-name>
    <servlet-class>org.nanocontainer.nanowar.webwork.PicoWebWork2ServletDispatcher</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

WebWork 2.1 Configuration

Map ServletRequestContainerFilter and PicoObjectFactoryFilter to WebWork's ServletDispatcher. In web.xml:

<filter>
    <filter-name>NanoWar</filter-name>
    <filter-class>org.nanocontainer.nanowar.ServletRequestContainerFilter</filter-class>
</filter>

<filter>
    <filter-name>NanoWar-WebWork2</filter-name>
    <filter-class>org.nanocontainer.nanowar.webwork.PicoObjectFactoryFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>NanoWar</filter-name>
    <servlet-name>WebWork</servlet-name>
</filter-mapping>
                                                                                
<filter-mapping>
   <filter-name>NanoWar-WebWork2</filter-name>
   <servlet-name>WebWork</servlet-name>
</filter-mapping>

Do not use the PicoServletDispatcher when using WebWork 2.1

Powered by Atlassian Confluence