|
The DWR (Direct Web Remoting) project is an open source solution under the Apache license for the developer who wants to use AJAX and XMLHttpRequest in an easy way. It has a set of JavaScript functions that remove the complexity from calling methods in a Java object running on the application server from the HTML page. It handles parameters of different types and helps keep the HTML code readable. In this example, you'll learn how to stream data to TIBCO General Interface? using DWR 2.0's "Reverse Ajax" features and the publish and subscribe interfaces of the OpenAjax Hub. Using DWR version 2.0 can make it very easy to add chat functionality to an application, allowing updates to be pushed from the server to the browser or browsers so that all users are aware of changes made. DWR's reverse Ajax introduces a very neat way to manage this transfer of information. It takes responsibility for deciding which techniques (polling, comet or piggyback) are best to use in each situation. It is easy to implement, thereby leaving the programmer free to concentrate on developing other areas of her application. In "Ajax Form Validation Using Spring and DWR," I presented a design to use Ajax to perform client-side validation by invoking an application's server-side validation logic. The whole point was to easily leverage validation logic on the server to prevent duplication of code, to reduce the time and cost of development and maintenance, and to enhance the usability of a web application. Few non-trivial software designs get it right the first time. This design has been running in production systems for over a year (its publication is approaching the ten-month mark), and has shown some limitations. This article discusses the emerged limitations and then presents an improved design that not only addresses the limitations but provides added functionality. Conceptually, the two designs are very similar, and a familiarity with the previous article, or working knowledge of Ajax, DWR, and the Spring Web MVC framework, are assumed. Using the jPetStore sample application, this article discussed and demonstrated a design for a generic and reusable Ajax form validation solution. Using existing open source projects and leveraging your applications validation logic, the development time and complexity required to implement this solution into your applications is minimal. After setting up the necessary infrastructure (and possibly some minor refactoring to existing applications), the largest effort will probably be simply adding onChange() event listeners to the HTML form input elements you'd like to validate via Ajax. While this article made use of the Spring and DWR frameworks, nothing about Ajax or the Ajax validation concepts presented here are tied to any particular tool, framework, or language, and implementations can be created in any way that fits your particular technical or business requirements. Using DWR can make creating cross-browser AJAX websites very easy, and introduces a very neat way to interact between JavaScript in the web browser and Java on the server. It is simple to get started with and integrates well with your current website. Portlets and Ajax would seem to be a perfect fit for one another, as they are both focused on using a Web browser as the vehicle for presenting a UI to the user. An easy way to combine the two with Java technology is to use the DWR library. DWR is a Java library, open sourced under the Apache license, for building Ajax-based Web applications. DWR's basic purpose is to hide Ajax details from the developer. You use plain old Java objects (POJOs) on the server side, and DWR dynamically generates JavaScript proxy functions so that client-side development with JavaScript feels like calling JavaBeans directly. The main component of DWR is a Java servlet that handles calls from browser to server. In this article, I will discuss the Direct Web Remoting (DWR) technology developed by Joe Walker and maintained by the small IT consultancy Getahead in UK. This technology is a unique way of Ajax-enabling existing Java server-side code by exposing it in JavaScript. This sounds complicated but, in reality, the technology is relatively straightforward. It has some limitations, such as exposing overloaded Java methods or marshaling of very complex Java Objects to JavaScript and will work only in a web application server. But overall, DWR is a very powerful concept that works with any existing Java web application and makes the process of web remoting easier. |
w_ww._j___a_v_a2__s_._c___o_m__ | Contact Us |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |