Chapter 10. Google Web Toolkit

In June 2006, Google announced a new product at the JavaOne conference: the Google Web Toolkit (GWT). GWT represents a completely new way of building Ajax applications: rather than writing HTML (or JSPs, or JSF pages) and JavaScript, with Java servlets or JSF components to handle the server side of the application, GWT lets you write the whole application, from client to server, in Java. It generates all the JavaScript automatically, based on the Java code you write. You still need to write some HTML, but GWT provides skeleton HTML as a starting point.

Being able to write the whole application in Java is an advantage, but that’s far from the whole story. After all, neither HTML nor JavaScript is that difficult to write. Another major benefit is that GWT handles all cross-browser issues for you. Even better, it provides hooks for full round-trip debugging. That’s right, you can debug the client code and the server code all with one IDE!

The trick to debugging the client code is the GWT client libraries. They are written in Java; when compiled, they are converted to JavaScript and HTML. In “hosted mode,” the client code is still in Java and can be debugged.

Getting Started with GWT

To get started with GWT, you must:

  1. Download and install a JDK.

  2. Download and install GWT, available from http://code.google.com/webtoolkit.

  3. Write some code and build your app.

Let’s start with step 3; the first two steps are trivial. Figure 10-1 shows what the sample application we ...

Get Ajax on Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.