Google Web Toolkit
If you are a Java software and Ajax developer, chances are the Google Web Toolkit (GWT) has already grabbed your attention.
Google released this free toolkit, under an Apache-style license, in May 2006. The GWT is designed for writing Ajax applications in the Java language. Google has initially made available beta versions for Windows and Linux, with a promise to add a Mac OS X version later on.
This article describes the development of a simple Ajax application on Mac OS X using GWT and familiar Java tools, such as Apache Ant, the Tomcat 5.0 servlet container, and the IntelliJ IDEA integrated development environment (the latter is a commercial IDE). The article assumes some knowledge of Java and Ant.
Using Ant with GWT
Using the GWT beta involves two modes of development: host mode and web mode.
Host mode is an intermediate development step that uses an embedded GWT browser; in this mode, your compiled code continues to run in a Java Virtual Machine (JVM). Host mode, however, is not available to us Mac OS X users hitching a ride on the Linux version. Host mode will be available once a Mac OS X version is released.
Web Development of a Different Flavor
This article delves into some of the typical web development related tasks GWT developers are likely to confront while creating services for Remote Procedure Calls (RPCs). RPCs are a part of a software model designed for the applications that use service oriented architecture (SOA). These development tasks include:
- Automating the development and deployment steps with a build file (the build runs the GWT compiler, then deploys the compiler's output plus your server-side Java class files to a servlet container like Tomcat, Jetty, or Resin).
- Viewing the HTML generated by the GWT application using Firefox's DOM Inspector.
- Redesigning the widgets on the page without access to the underlying HTML (since you are using GWT's Java API).
- Making sure the HTML is legal markup, for instance, based on a particular XHTML document type required by your organization.
At Your Service
First, I'll briefly describe the service that this application creates. It is designed to illustrate the model that GWT uses.
The application displays a form in a browser, requesting that the user enter their name, age, and country of origin. When the user submits the form by clicking a button, the application displays a server response in a textarea, without initiating a page refresh. Figure 1 shows what the application looks like in the Safari browser.
Figure 1: A simple view generated by GWT
When the user clicks the
OK,Submit button after leaving a TextBox blank, for instance, Figure 2 shows the result.
Figure 2: The application displays an error message in red