Jawr supports DWR 2.x using the jawr-dwr2.x-extension extension module. Maven users can add a dependency as the following:
<dependency> <groupId>net.jawr.extensions</groupId> <artifactId>jawr-dwr2.x-extension</artifactId> <version>3.8</version> </dependency>
There is a sample application that you can download to check out how integration with DWR works, which you can download from this link.
Jawr supports also DWR 3.x using the jawr-dwr3.x-extension extension module. Maven users can add a dependency as the following:
<dependency> <groupId>net.jawr.extensions</groupId> <artifactId>jawr-dwr3.x-extension</artifactId> <version>3.8</version> </dependency>
The jawr servlet must be started after the DWR one. To make sure this order is followed, you must set up the load-on-startup parameter so that the value for the Jawr servlet is greater than the one for the DWR servlet:
Jawr needs to know the servlet mapping that points to DWR. Therefore, in the properties config you must set up the jawr.dwr.mapping parameter to the same value (without the wildcard) that you use for the DWR servlet:
Web.xml: <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> Jawr.properties: jawr.dwr.mapping=/dwr/
If you declare more than one DWR servlet, Jawr will need to access the additional mappings for these. In this case, for every additional servlet you must add a special init-param, named jawr_mapping. The value, again, must be the servlet-mapping used for the servlet, without the wildcard. Note that this init-param is added to the DWR servlet config, not the Jawr servlet config.
<servlet> <servlet-name>additional-dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <description>Direct Web Remoter Servlet</description> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> ... <init-param> <param-name>jawr_mapping</param-name> <param-value>/other/dwr/</param-value> <-- Matches servlet-mapping </init-param> ... </servlet> <servlet-mapping> <servlet-name>additional-dwr-invoker</servlet-name> <url-pattern>/other/dwr/*</url-pattern> <-- Use in jawr_mapping </servlet-mapping>
You need to do this for additional DWR servlets, but you can skip it for the one to which mapping you point in the jawr.dwr.mapping param. You can’t skip using this param though, since it acts as a flag to Jawr indicating that DWR integration is on.
A specific generator is used for dwr resources (check below for more information on dwr resources). Prior to the 3.5 version, this generator was a built-in generator, now users must declare it specifically in their jawr configuration file. To render the DWR bundles properly, the declaration of a specific DWR JS bundle link renderer is needed.
For dwr 2.x, users will need to use the following configuration :
# Configure DWR generator and DWR link renderer jawr.custom.generators=net.jawr.web.resource.bundle.generator.dwr.DWRBeanGenerator jawr.js.bundle.link.renderer.class=net.jawr.web.resource.bundle.renderer.DWRJsBundleLinkRenderer
For dwr 3.x, users will need to use the following configuration :
# Configure DWR generator and DWR link renderer jawr.custom.generators=net.jawr.web.resource.bundle.generator.dwr.DWR3BeanGenerator jawr.js.bundle.link.renderer.class=net.jawr.web.resource.bundle.renderer.DWRJsBundleLinkRenderer
|dwr:_actionutil||DWRActionUtil.js (webwork integration)|
The engine.js script should always be included first since others depend on it. Note that this file is not completely static, since DWR generates some variables depending on the user’s request. This is not optimal, since users will get a new copy on every new session with the application. Jawr solves this by generating these parameters in a very small inline script that contains only the dynamic variables.
# Configure DWR generator and DWR link renderer jawr.custom.generators=net.jawr.web.resource.bundle.generator.dwr.DWRBeanGenerator jawr.js.bundle.link.renderer.class=net.jawr.web.resource.bundle.renderer.DWRJsBundleLinkRenderer # Configure DWR bundle jawr.js.bundle.global.id=/bundles/global.js jawr.js.bundle.global.mappings=/js/protaculous/**, dwr:_engine, dwr:_util jawr.js.bundle.global.global=true
For instance, the following mapping adds two of these beans to a bundle:
Note that Jawr does not support having several DWR servlets that map to beans with the same names. You can’t declare two DWR servlets with a bean named ‘Person’, for instance.
One last thing you can do is to bundle all dwr beans into one bundle. To do this, tou use the special keyword dwr:_**:
This adds all beans defined in dwr.xml: jawr.js.bundle.alldwrbeans.mappings=dwr:_**
Be aware that this mapping does not include the static DWR scripts, only the bean stubs. Here is an example of an all-in-one DWR bundle:
jawr.js.bundle.dwrall.id=/bundles/dwrall.js jawr.js.bundle.dwrall.mappings=dwr:_engine, dwr:_util,dwr:_auth, dwr:_**