Skip to Content

Scared of writing AJAX code?

Do not want to get into intricacies of event based JavaScript?

Are you a Java developer with no prior scripting experience but still have to write AJAX based applications?

Here comes GWT for your rescue!!!! Google™ has launched the Google Web Toolkit (Beta) and is looking forward to receive feedback from the developer community. You can download it here, and give a try.

Here’s a summary of why you should use GWT.

  • Use any Java IDE of your choice to write / run / debug the Java code which does what you want your AJAX code to do.In other words, the event based programming which you otherwise do in Javascript,similar code needs to be written using Java.Off course,you need to use the special API of GWT, which exposes the UI related functionality. Preferably, use an Eclipse based IDE because GWT also gives a choice of generating Eclipse compliant project.
  • After you are done with the Java development, take a break , and let the Java-to-JavaScript compiler of GWT do the rest for you, which will generate JavaScript and HTML files which you can run in the Web Server of your choice.

Check out the Product overview & FAQs sections for features,licencing and other details.

Steps to create an Eclipse based GWT application:
From the extracted directories of the downloaded archive, locate the utility files by name projectCreator and applicationCreator(located in the root directory and you can also put this directory onto your path). These utility can generate the necessary files that are required for a perfect project structure in Eclipse.

See the snapshot below which illustrates the command steps to create a HelloWorld project strcture and application with GWT.
Command steps

The output from the above commands is a project structure as expected by Eclipse and the batch files HelloWorldApplication-compile.cmd and HelloWorldApplication-shell.cmd which are for Java-To-Javascript compilation and running the application in hosted mode respectively.
Note that you need to import the contents of the generated folder into Eclipse using the Import –> Existing Project into Workspace option.

Run the HelloWorldApplication-compile.cmd script and you can see that a folder www gets generated which has the html files and the script files containing AJAX code.

I modified the standard generated code a bit to make it accept the user name as input and the output says Hello to the user and tells at what time on the server the user has visited this page…again…ALL ASYNCHRONOUSLY!!! That’s the magic of AJAX!!!

Find below the code for reference:

This was all about writing and running the code on your local machine / test environment and won’t do any good for your realtime scenario. What when you want to point your AJAX enabled pages to a server side implementation, say a J2EE Web Application? The answer is GWT RPC framework. You still generate your AJAX code using GWT tools and point them to the server side implementation using RPC.

This page lists the Java packages & classes that you can refer to inside your GWT based code.If you try to use the classes which are beyond these,running the Java-To-Javascript compiler results into error.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply