Thursday, March 11, 2010

Spring and DWR Integration Setp by Step

It’s been a couple of years since I used DWR last time. After spending sometime on configuration I got it working on my current project with the following configuration. Add the following xml file to your project along with other spring context files you have. You can download xml file from my site seenuonjava.com


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">

<dwr:controller id="dwrController" debug="true" />

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true" />
<property name="order" value="3" />
<property name="mappings">
<props>
<prop key="/dwr/**/*">dwrController</prop>
</props>
</property>
</bean>

<!-- Java Class that DWR calls -->
<bean id="dwrContractNumCheck" class="com.seenu.test.dwr.ContractsNumCheckDwr">
<!--DWR generated JavaScript name for above java class-->
<dwr:remote javascript="dwrContractNumCheck">
<!--Method for DWR to be included in the above JavaScript-->
<dwr:include method="checkNumOfContracts" />
</dwr:remote>
</bean>

<!--
Call to the above method returns Contract object,
so define a converter for it
-->

<dwr:configuration>
<dwr:convert type="bean" class="com.seenu.test.entity.Contract" />
</dwr:configuration>

</beans>


In my next post I will talk about end to end example.

1 comment:

Anonymous said...

Good dispatch and this post helped me alot in my college assignement. Say thank you you as your information.