- Implement a Java class that will act as the remote interface. It can be any Java class with any methods.
- Configure DWR in the WEB-INF/dwr.xml file defining the methods to be exposed as shown below.
<dwr>
<allow>
<create creator="new" javascript="JavascriptName">
<param name="class"
value="JavaClassName"/>
<include method="method1"/>
<include method="method2"/>
</create>
<convert converter="bean"
match="beanType">
<param name="include"
value="attr1,attr2,..."/>
</convert>
</allow>
</dwr> - Define the DWR Servlet in your web.xml file:
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping> - Invoke the methods from client-side Javascript using the notation:
JavaScriptName.methodName(methodParams ..., callBack)
Where the callBack method handles the data returned from the server. You will have to include engine.js and util.js available from the DWR site.
References:
No comments:
Post a Comment