Tuesday, January 24, 2012

A quick look at Ajax & GWT

Ajax stands for Asynchronous Javascript And Xml which is used to create rich ajax based websites to improve end user experience. The theory behind ajax is, through ajax, the web page is not reloaded every time a request is made, but only the part of it(content change). To be more specific, with AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade(exchange) data with a web server, without reloading the page. This is done through javascript enzine of your browser. Our fevorite sites, Gmail, Google Suggest, Google maps all operate on ajax.  So they are highly interactive.

Ajax is a not new technology nor it’s  a new programming language in itself, but a new way to use existing standards. To achieve ajax functionalities, we need to know bit of javascript.There are interesting technologies available today which make development of ajax applications much easiar than you imagine. These include DWR (Direct Web Remoting), YUI Toolkit (Yahoo User Interface) & GWT (Google Web Toolkit). Just to give you an idea, you call a java method from your javascript using DWR(http://getahead.org/dwr).  YUI is a library of javascript functions which aid the development of rich UI (http://developer.yahoo.com/yui) & GWT. Among these, GWT is faster way for ajax based website development.


GWT has only one important objective. ‘You can develop a rich AJAX Web applications easily without any javascript code but through Java’. And it’s true, all you have to know is Java  programming language(good news for people who hate javascrit!) The heart of GWT is GWT Compiler that converts Java code into Javascript & ensures cross browser compitability. You develop, debug your web application in Java. 

What is Google Web Toolkit?

Google Web Toolkit (GWT) is an open source Java development framework that lets you escape the matrix of technologies that make writing AJAX
applications so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler translates your Java application to browser-compliant JavaScript and HTML. In a typical GWT application, UI is created from the client side & the UI generated events can be handled at the client side. Only to get the data(not the html page), a gwt application will connect to any web server. It does so by using it’s built in RPC mechanism. GWT application accesses the anybusiness functionality that exists at the server as a service.


Here’s the GWT development cycle:

1.Use your favorite Java IDE to write and debug an application in the Java language, using as many (or as few) GWT libraries as you find useful.
2.Use GWT’s Java-to-JavaScript compiler to distill your application into a set of JavaScript and HTML files that you can serve with any web server.
3.Confirm that your application works in each browser that you want to support, which usually takes no additional work.


GWT features:

1. Dynamic & Reusable components
2. Simple RPC
3. Real Debugging
4. Browser Compatible
5. JUnit integration
6. Internationalization
7. JSNI – Java Script Native Interface
9. Open Source – It’s completely open source

Simple GWT Code looks like:

public void onModuleLoad(){
Button b = new Button(”Click me”, new ClickListener()
{
   public void onClick(Widget sender)
  {
    RootPanel.get().add(new Label(”You clicked on Hello Button”));
 }
});
  RootPanel.get().add(b);
}Above code will create a button on html page & on click of it, puts a label mentioned.To explore more on GWT, visit www.code.google.com/webtoolkit/


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...