Introduction to WebWork action invocation through DWR

From WebWork 2.2.7, DWR integration is included with Webwork. You can find out more from the documentation on the Webwork Wiki.

WebWork support in DWR

There are a couple of things that you must do in order to be able to use WW actions through DWR.

Step 1: Configure dwr.xml

You must include in the dwr configuration file:

<create creator="none" javascript="DWRAction">
  <param name="class" value="org.directwebremoting.webwork.DWRAction"/>
  <include method="execute"/>
</create>

<convert converter="bean" match="org.directwebremoting.webwork.ActionDefinition">
  <param name="include" value="namespace,action,method,executeResult" />
</convert>

<convert converter="bean" match="org.directwebremoting.webwork.AjaxResult"/>

In case your AJAX WebWork action invocations return action instances (and not pure text), than you must include converter definitions for your action objects (package level or for individual actions).

<convert converter="bean" match="<your_action_package>.*"/>

Step 2: Import scripts in your JSP files

Follow the rules to enable DWR in your JSP actions. Also include the DWRActionUtil.js script (place it in your scripts web directory).

Usage

Invoking an action from JS is done using the following:

DWRActionUtil.execute(id, params, callback [, displayMessage]);

Where id is one of:

params must be one of:

And callback is either:

Finally displayMessage is an optional parameter which specifies a message to be displayed till request completion (see DWR documentation)

Advanced

You can declare a pre/post action processor by providing in web.xml through a context-wide initialization parameter (dwrActionProcessor). The processor must implement org.directwebremoting.webwork.IDWRActionProcessor interface. The processor will be invoked before and after the action has been invoked, so that you can prepare the initial invocation or change the result.