DWR - Ajax made easy

Web Users wants more!
Web users are now demanding web applications to be interactive in nature and as responsive as their desktop applications. The interactive nature of Desktop applications seems out of reach for web based applications until a new approach came to be known as AJAX (Asynchronous JavaScript and XML). AJAX is a convergence of different technologies so that web applications can mimic the interactive nature and responsiveness of Desktop applications. I want to use AJAX Now! There are several AJAX frameworks that can be used and DWR is one of the most popular Ajax frameworks out there. There are 3 ways of how AJAX interaction are designed:
1. Content-Centric
This approach will directly insert HTML into the client page
2. Data-Centric
Information or data is received from the server in XML or JSON.
3. Script-Centric
JavaScript code is received from the server. The response from the server will include JavaScript code.
Among the 3 ways above i prefer the Data-Centric approach as it gives us a cleaner separation between the data that we need to present and the logic on how we present it, but we need to parse the data coming from the server and manipulate the HTML elements of the DOM to generate the appropriate output. This will give you more flexibility with regards on how you want to present the data that came from the server versus getting HTML code (Content-Centric) or JavaScript Code (Script-Centric) because it will be harder to reformat HTML Code and or manipulate JavaScript Code in the receiving client page.

Hello, DWR
DWR is one of the easiest Ajax frameworks that I tried. Compared to GWT, GWT has a high learning curve. DWR is easy to deploy and can easily be integrated with existing display vehicles like JSP and HTML.
  
Here is a simple example that I have created:
1.
First I created a simple Web Archive. Added the dwr.jar and commons-logging-1.1.1.jar in under the WEB-INF/lib folder


2. Then I created a dwr.xml under the WEB-INF folder which will identify the class would be used as a JavaScript .

3. Here is the source code of the Class that I used. This is just a POJO with one method that accepts a String that will return a String

4. I created an HTML page. Take note of the script tags inside the head tag. You can get that URL of the script under the /dwr/test/index.html, this URL will allow you to test the methods that you created in Java.

5. Then the result will be something like this and that was it.



What i have learned

DWR was easy to learn and apply. You can quickly incorporate AJAX functionality to existing JSP and HTML pages. DWR can be easily mixed with existing JavaScript library.
Here are the downside that I can see :
1. You need to have good JavaScript skills to manipulate the HTML DOM.
2. Debugging can be pain, unless you have the proper tool and is a seasoned JavaScript Developer
3. You have to deal with cross-browser compatibility.
But overall, I think DWR is not that bad to quickly sprinkle your web application with AJAX bells and whistle.

Comments

Popular posts from this blog

OAuth 1.0a Request Signing and Verification - HMAC-SHA1 - HMAC-SHA256

Spark DataFrame - Array[ByteBuffer] - IllegalAurmentException

Gensim Doc2Vec on Spark - a quest to get the right Vector