Integrating DWR with Struts

DWR can work with almost any framework.

There are 2 levels at which DWR will work with Struts. The most basic level just involves using both at the same time, which is perfectly possible, but it does not allow you to share actions between DWR and Struts.

DWR can call any method so there is nothing to stop you from calling a Struts action from DWR, except that you don't want to do that. What would be the contents of the ActionForm? and what would DWR do with the returned ActionForward?

A good approach is to refactor the Actions you wish to call so the logic is extracted from the Action. DWR and your Action then call the same method.

The 'struts' Creator

The StrutsCreator is included with the normal DWR download. You can use this from dwr.xml as follows:

  <create creator="struts" javascript="ScriptName">
    <param name="formBean" value="formBeanName"/>

This will allow you to make calls into your FormBeans from DWR.

Startup Ordering

If you are using the StrutsCreator then you should ensure that Struts is initialized before DWR. You do this by ensuring that your web.xml has a <load-on-startup> value that is lower for Struts than for DWR.