Google Web Toolkit Tutorial - douglasjose.comhttp://douglasjose.com/tech/tutorials/gwt.htm1 of 53/23/2008 14:17
Google Web Toolkit Tutorial
July, 20Learn to write AJAX applications from Java classes, using the new development paradigm introduced by this new Google framework.Recently, the 1.20 version of Google Web Toolkit (GWT) was released. This framework introduces a new AJAX application development paradigm. Is goal is tohide from programmer the JavaScript code implementation, considering this job is repetitive, error-prone and full of tedious tasks, like browser incompatibilityhandling.GWT abstracts JavaScript using a Java class library, where a visual AJAX components (the
widgets
) library is available. These components are well known byGMail and Google Maps users.This tutorial presents how GWT changes the application development paradigm, and brings an implementation sample using the framework.
Java classes advantages
The main feature presented by GWT is the Java class usage to represent AJAX visual components. These classes are converted to JavaScript code by acompiler, distributed inside GWT package.The advantage of using Java code is that it enables the developer to use its preferred Java IDE, once GWT is environment-independent. And when using a JavIDE, you benefit from Java language features, like compiler type checking and editor code completion.
Framework architecture
A model of GWT architecture is presented below.The architecture is split in two big layers. The first one is the libraries layer. This layer has a visual components layer, which represents user interfacecomponents, and a Java emulation library, that contains the implementation of some classes from
java.lang
and
java.util
packages. These two libraries composthe basic infrastructure necessary to represent the AJAX components using Java code. The other layer contains two tools. The first is the Java to JavaScriptcompiler, which is responsible by generate the JavaScript code which represents the visual components. The second tool is a local browser. This browserprevents the developer from converting is Java into JavaScript code every time he wants to do a test. The local browser is able to render the library componentswithout code conversion.
Installation
The first step to use GWT is to download the package from framework site. It's currently available to Windows and Linux. In this tutorial we're going to presentconfiguration instructions to Windows, remembering that the procedures almost the same for Linux. This tutorial was built using GTW version 1.0.20. Thepackage is distributed in a zip file, and its size is 13.9 MB.The installation is very simple: just unzip the distribution package in a local directory. In this directory will be created the GWT libraries and some projectconfiguration utilities.This tutorial will be written using Eclipse WTP. This IDE was choose because GWT brings tools that simplify the project creation step for Eclipse.
Creating a project
So let's start coding. First of all, we're going to create a project and an application. To do that, we'll use two utilities,
applicationCreator
and
projectCreator
. It'snecessary to create a directory where the project files will be placed. Add the GWT directory to the environment variable
PATH
, to make project creation easierand from project's directory, run the command
projectCreator -eclipse TutorialGWT
to create the project, and then, run the command
applicatoinCreator -eclipse TutorialGWT br.com.javamagazine.client.TutorialGWT
The basic Eclipse project structure will be created, with GWT libraries references already configured. At Eclipse, just import the created project (Menu
File>Import>Existing projects into workspace
), and the configurations will be automatically set up. The project structure should be similar to the presented belo
Add a Comment
venomouslid16left a comment
deleted_fbuser_1301915674left a comment
Kishore Java replied: