From WebWork 2.2.7, DWR integration is included with Webwork. You can find out more from the documentation on the Webwork Wiki.
There are a couple of things that you must do in order to be able to use WW actions through DWR.
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>.*"/>
Follow the rules to enable DWR in your JSP actions. Also include the DWRActionUtil.js script (place it in your scripts web directory).
Invoking an action from JS is done using the following:
DWRActionUtil.execute(id, params, callback [, displayMessage]);
Where id
is one of:
DWRActionUtil.execute('/ajax/TestFM', 'myform', 'doOnTextResult');
xwork.xml
. It must specify the following fields:
E.g.:
DWRActionUtil.execute({ namespace:'/ajax', action:'TestJS', executeResult:'true' }, 'data', doOnJSResult, "stream...");
params
must be one of:
{}
to ignore any parameters.
Example:
DWRActionUtil.execute('/ajax/TestFM', {}, doOnJSResult, "stream...");
Example:
<input id="mytext" name="mytext" value="some value" type="text"/> DWRActionUtil.execute('/ajax/TestFM', 'mytext', doOnJSResult, "stream...");
Note: If your action configuration in xwork.xml uses the parameters interceptor than your action will be initialized correctly with the parameters values. For more documentation, please consult WebWork available documentation.
And callback
is either:
Finally displayMessage
is an optional parameter which specifies a message to be displayed till request completion (see DWR documentation)
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.