DWR (Direct Web Remoting) is a Java-based toolkit that facilitates asynchronous communication between a web server and client using Ajax techniques. It allows calling Java methods on the server directly from JavaScript. DWR handles marshalling requests and responses between the two environments using JSON. Some key advantages of DWR include tight integration with Spring, hiding of XMLHttpRequest details, and ability to use other UI libraries alongside it.
4. Examples of AJAX GMail Google Maps Google Suggest Flickr
5.
6. Why DWR? Most commonly used toolkit in java environment according to Google and Burton Group (research and advisory services in IT architecture and infrastructure decisions) Java to JavaScript marshalling and vice versa Integrates best with Spring! Uses JavaScript objects also called JSON(Java Script Object Notation)
7. Why JSON? Lightweight data-interchange format Easy for humans to read and write Easy for machines to parse and generate var myJSONObject = { "web":[ { "name": "html", "years": "5" }, { "name": "css", "years": "3" }] } JSON Vs XML: Light and Faster than XML. JSON types: String, number, array, boolean but XML all strings. Reading values from JSON object is same as java object, but reading XML needs tedious DOM APIs.
10. DWR configuration steps 1.Copy dwr.jar to lib folder 2. Add DWR servlet details in web.xml 3. Create dwr.xml in web-inf folder to configure DWR 4. Write Java classes that dwr will use for Ajax functionality 5. Call methods of those classes from Java script.
11.
12.
13. DWR Advanced features Batching: beginBatch() make some dwr request endBatch() Accessing servlet parameters: WebContext ctx = WebContextFactory.get(); ctx.getHttpServletRequest(); ctx.getHttpServletResponse(); ctx.getServletContext(); GMail style loading messages DWRUtil.useLoadingMessage(‘Waiting…’);
14. DWR Scriptaculous Dojo Prototype 1. Java-exclusive -- seems to be Java code that generates JavaScript. This limits its utility in non-Java environments. 1. No IE5.x support 1.Documentation is lacking. 2. Client has to include large size javascript files. 1.IE support is limited to IE6. 2. No documenta- tion other than Readme!!. 3. Has no visual effects library. 1. Good integration with Java. 2. Extensive documentation . 3. Integration with projects (Spring, XOM, Dom4J) 1. Lots of neat visual effects. 2. Simple and easy to understand object-oriented design. 1.Browser compatibility targets are: IE,FireFox,Safari. 2.Core parts are unit tested, has good visual effects 1.It can be used in any environment. 2. Foundation for other toolkits. 3. Provides fairly low-level access to XMLHttpRequest. C O N S P R O S
15. Conclusion DWR improves the user experience. Integrates nicely with Spring. Testing DWR functionality is easy by setting debug to true. Hides XMLHttpRequest javascript implementation. Can be used along with other UI toolkits(eg. Scriptaculous, Dojo…) etc…