Tien Soon's Tech Blog

 

Sharing the latest buzz in Information and Communication Technology sector.

Tuesday, May 23, 2006

Ajax with Google Web Toolkit

Google is better known as the generous technology giant that offers plenty of useful Web-based applications and services at no cost. However, to developers, Google is also the generous contributor of heavy-weight APIs and open source projects, particularly in its Google Code initiative.

The Internet technology world is currently surrounded by tons of Ajax thingy, Ajax-ified applications, Ajax frameworks, Ajax development tools, and more. Google is not only one of the early pioneers to publicly release Ajax-powered applications for end-user environment, but now in the forces of releasing Java-based Ajax framework to ease development pains as well.

If you've not guessed it right, Google Web Toolkit (GWT) is Ajax framework recently released by Google.

I have a feeling that the GWT is actually the core engine behind Google's Ajax-ified applications like Google Maps and Gmail. Possibly it's the framework that Google has been using all this while to develop their top-notch applications that attracted the world's focus towards a new user interaction paradigm.

What is GWT?

GWT is the Java-based Ajax framework that allows you to code everything in Java, including the front-end, and the equivalent components will be automatically converted into JavaScript and HTML without you worrying the management of asynchronous calls or DOM concepts.

Following are the summarized highlights of GWT.

Reusable UI Components and Widgets

Similar to Java Swing, GWT is featuring a wide collection of UI components, which can be coded in Swing-like Java codes. These components will be converted into HTML at deployment time. Like any other component-based framework, the pre-built UI components save development time. The default look-and-feel of the widgets are very Google-like, you may opt for customization by changing the appropriate CSS.

RPC

GWT accomplishes the communication between web application client and back-end server with Remote Procedure Call (RPC). You will first need to create a service Interface, which is to be implemented by a servlet. An Interface which supports asynchronous call also defines a callback mechanism to perform some programmer-defined tasks when the Ajax call is succeeded or failed.

No worry, you need not be a hard-core RPC developers to accomplish this model. The fundamental interfaces to be implemented and classes to be extended should give you a guided idea of how the model should flow.

Browser History Management

Everyone says Ajax is cool, but browser history management remains a big issue. Since the browser is not reloaded, most of the time Back button doesn't work as expected for moving forward and backward in browser history.

GWT has solved this issue, by keeping the history in stack. You can programmatically move forward and backward in the history stack.

Not long ago, ONJava.com has also published an article titled “AJAX: How to Handle Bookmarks and Back Buttons” to discuss on the proposed solution for managing browser history in Ajax application.

Real Debugging

GWT is not only Java-based, but fully supporting real Java debugging as well. During development, the codes are running in JVM (Java Virtual Machine), which allows you to debug your code in debugger, such as Eclipse IDE. This is something lacking in other existing Ajax frameworks I've tried out so far.

Browser Compatibility

Read:
Your GWT applications automatically support IE, Firefox, Mozilla, Safari, and Opera with no browser detection or special-casing within your code in most cases

Since Ajax is heavily powered by JavaScript, browser compatibility is one of the core issues until today. Every developer who has worked with JavaScript will surely hate the process of debugging JavaScript codes for cross-browser compatibility. Different browsers are interpreting and supporting the syntax in varying ways, which makes maintenance of JavaScript codes a headache.

This is the reason why Ajax framework comes into place. When cross-browser compatibility issue is fully handled at framework level, developers can better concentrate on the logic and functionalities.

Put in Your Own JavaScript

When it says “the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML”, the first thing came into my mind was “what if I want to mix in my own JavaScript?”

Yes, the possibility exists. No matter how powerful the GWT framework is, still, there might be times when you need to add in some JavaScript codes on your own to handle some additional functionalities that are not implicitly featured in the framework. This can be done using JavaScript Native Interface (JSNI).

First time I came across JSNI, but the concept is similar to JNI (Java Native Interface).

My Favorite Ajax Framework

Currently, my favorite Ajax framework goes to DWR. I've yet to have some hands-on for GWT, let see whether GWT will change my preference :-)

1 Comments:

  • At May 23, 2006 7:23 PM, Blogger Shishank said…

    Pretty good post !!
    I do not know much about DWR, but what nakes GWT interesting is that it uses Java coding style. It's a pity that very few people really know JS and are confortable writing BIG Java applications. So this really helps. Also, the framework provide one place where you can run,test applications without any dependency on any other environment.

    BR,
    Shishank
    http://www.pcmspace.com

      Edit Comment

Post a Comment

Links to this post:

Create a Link

<< Home