|
|
Hi there,
I just wanted to share my working configuration of DWR/Spring 2.0.8 to people who have problems setting it up. This post intends to help anyone who is having issues or anyone who is interested in using it or it’s planning to have a go at it in the future.
Although some people didn’t have any problem setting up DWR, others are not so lucky. I hope this post helps them out.
My webapp had the need to provide feedback when generating big files. This feedback translated naturally into a progress bar.
My set up: DWR 2.0.x, Spring 2.0.8, Tomcat 5.5.23
Spring configuration files
1) Web.xmllt;servlet-mappinggt; lt;servlet-namegt;TD_SampleDataGeneratorlt;/servlet-namegt; lt;ucl-patterngt;*.htmllt;/ucl-patterngt; lt;/servlet-mappinggt;
lt;servlet-mappinggt;
lt;servlet-namegt;TD_SampleDataGeneratorlt;/servlet-namegt;
lt;ucl-patterngt;/dwr/*lt;/ucl-patterngt;
lt;/servlet-mappinggt;
No need for dwr.xml. Also notice that I’m using the same controller to handle webapp + dwr behaviour.
Notes:
I originally had the below entry, but for some reason It didn’t work for me. Even though the app deployed properly with no error logs, the dwr debug page was empty. DWR didn’t know about my classes..
lt;!—By the documentation, this entry should have worked, but it didn’t work for me… - --gt;
lt;servletgt;
lt;servlet-namegt;dwr-invokerlt;/servlet-namegt;
lt;servlet-classgt;org.directwebremoting.servlet.DwrServletlt;/servlet-classgt;
lt;init-paramgt;
lt;param-namegt;debuglt;/param-namegt;
lt;param-valuegt;truelt;/param-valuegt;
lt;/init-paramgt;
lt;/servletgt; lt;servlet-mappinggt;
lt;servlet-namegt;dwr-invokerlt;/servlet-namegt;
lt;ucl-patterngt;/dwr/*lt;/ucl-patterngt;
lt;/servlet-mappinggt;
2) TD_SampleDataGenerator-servlet.xml (whatever your [webapp]-servlet.xml is)
Add the corresponding namespaces
lt;beansxmlns=quot;schema/beansquot; xmlns:xsi=quot;2001/XMLSchema-instancequot; xmlns:aop=quot;schema/aopquot; xmlns:dwr=quot;schema/spring-dwrquot; xsi:schemaLocation=quot;schema/beans schem...-beans-2.0.xsd schema/aopschem...ng-aop-2.0.xsd schema/spring-dwr schema/spring-dwr-2.0.xsdquot;gt;
lt;!-- DWR - --gt;
lt;dwr:controller id=quot;dwrControllerquot; debug=quot;truequot; /gt;
lt;!—If DWR needs to have access to app beans to share info. In my case I needed StatusBean to read values that will modify my progressbar- --gt;
lt;dwr:configurationgt;
lt;dwr:convert type=quot;beanquot; class=quot;com.myDomain.remote.StatusBeanquot; /gt;
lt;/dwr:configurationgt;
lt;!— com.myDomain.remote.StatusRecordProgressListener is the class that will be published to DWR. getStatus is the method that will be invoked from DWR through Javascript
I forced the use of CGLIB setting proxy-target-class=true as per Spring 2.0.8 doc section 6.6- --gt;
lt;bean id=quot;recordProgressListenerquot; class=quot;com.myDomain.remote.StatusRecordProgressLis tenerquot; scope=quot;sessionquot;gt;
lt;dwr:remote javascript=quot;StatusRecordProgressListenerquot;gt;
lt;dwr:include method=quot;getStatusquot;/gt;
lt;/dwr:remotegt;
lt;aop:scoped-proxy proxy-target-class=quot;truequot;/gt;
lt;/beangt;
lt;!— The section is only to show where the above bean is injected - --gt;
lt;bean id=quot;fileGeneratorControllerquot; class=quot;com.myDomain.controller.GenerateFileControl lerquot;gt; lt;property name=quot;recordProgressListenerquot; ref=quot;recordProgressListenerquot;/gt; …… other properties …
lt;/beangt;
lt;!— Handler mapping to access dwr resources (test pages, scripts, etc)- --gt;
lt;bean id=quot;dwrMappingquot; class=quot;org..web.servlet.handler.Sim pleuclHandlerMappingquot;gt; lt;property name=quot;alwaysUseFullPathquot; value=quot;truequot;/gt; lt;property name=quot;mappingsquot;gt; lt;propsgt; lt;prop key=quot;/dwr/**/*quot;gt;dwrControllerlt;/propgt; lt;/propsgt; lt;/propertygt;
lt;/beangt;
and with that It should work just fine.
After you deploy the webapp successfully (hopefully #9786;), go to [yourWebApp]/dwr/index.html
And you should see a list of the classes exposed to DWR. Based on the above example your should only see StatusRecordProgressListener
……
Classes known to DWR: * StatusRecordProgressListener (com.myDomain.remote.StatusRecordProgressListener)
……..
And that’s all.
I hope it helps and if you are interested in the whole set of java src’s + javascript…don’t hesitate to contact me.
Cheers,
/F |
|