Book Image

Google Web Toolkit GWT Java AJAX Programming

By : Prabhakar Chaganti
Book Image

Google Web Toolkit GWT Java AJAX Programming

By: Prabhakar Chaganti

Overview of this book

<p>GWT Ajax Programming shows you how to create reliable user interfaces that enhance the user experience.<br /><br />GWT is an open source Java software development framework that makes writing AJAX applications like Google Maps and Gmail easy for developers who don't speak browser quirks as a second language. Writing dynamic web applications today is a tedious and error-prone process; you spend 90% of your time working around subtle incompatibilities between web browsers and platforms, and JavaScript's lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile.<br /><br />GWT lets you avoid many of these headaches while offering your users the same dynamic, standards-compliant experience. You write your front end in the Java programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.</p> <h3>Chapter-by-Chapter</h3> <p><span style="font-weight: bold;">Chapter 1</span> introduces GWT, the download and installation of GWT, and running its sample application.</p> <p><span style="font-weight: bold;">Chapter 2</span> deals with the creation of a new GWT application from scratch, and using the Eclipse IDE with GWT projects, creating a new AJAX Random Quotes application, and running this new application.</p> <p><span style="font-weight: bold;">Chapter 3</span> deals with an introduction to and overview of GWT asynchronous services, and creating a prime number service and geocoder service.</p> <p><span style="font-weight: bold;">Chapter 4</span> deals with using GWT to build simple interactive user interfaces. The samples included in this chapter are live search, auto fillable forms, sortable tables, dynamic lists, and a flickr-style editable lable.</p> <p><span style="font-weight: bold;">Chapter 5</span> introduces some of the more advanced features of GWT to build more complex user interfaces. The samples included in this chapter are pageable tables, editable tree nodes, a simple log spy, sticky notes, and a jigsaw puzzle.</p> <p><span style="font-weight: bold;">Chapter 6</span> includes an introduction to JavaScript Native Interface (JSNI) and using it to wrap third-party JavaScript libraries like Moo.fx and Rico. it also includes using the gwt-widgets project and its support for the Script.aculo.us effects.</p> <p><span style="font-weight: bold;">Chapter 7</span> deals with creating custom GWT widgets. The samples included in this chapter are a calendar widget and a weather widget.</p> <p><span style="font-weight: bold;">Chapter 8</span> concerns itself with creating and running unit tests for GWT services and applications.</p> <p><span style="font-weight: bold;">Chapter 9</span> sees us using Internationalization (I18N) and client-side XML support in GWT.</p> <p><span style="font-weight: bold;">Chapter 10</span> includes the deployment of GWT applications using both Ant and Eclipse.</p>
Table of Contents (16 chapters)
Google Web Toolkit
Credits
About the Author
About the Reviewers
Preface
Running the Samples

Basic Download


We are going to download GWT and its prerequisites, install them to the hard disk, and then run one of the sample applications shipped with the GWT distribution to ensure that it works correctly.

Time for Action—Downloading GWT

In order to use the GWT, you will need to have Java SDK installed. If you do not already have the Java SDK, you can download the latest version from http://java.sun.com/javase/downloads/. Install the SDK using the instructions provided by the download for your platform.

Note

Java 1.4.2 is the safest version of Java to use with GWT, as it is completely compatible with this version, and you can be sure that your application code will compile correctly. GWT also works with the two newer versions of the Java platform—1.5 and 1.6; however, you will not be able to use any of the newer features of the Java language introduced in these versions in your GWT application code

Now, you are ready to download GWT:

  1. 1. GWT is available for Windows XP/2000, Linux, and Mac OS X platforms from the GWT download page (http://code.google.com/webtoolkit/download.html). This download includes the GWT compiler, hosted web browser, GWT class libraries, and several sample applications.

    Please read the Terms and Conditions of usage before downloading it. The latest version available is 1.3 RC 1, released December 12, 2006. Select the file for your platform. Here is a sample window showing the versions available for GWT:

  1. 2. Unzip the downloaded GWT distribution to your hard disk. It will create a directory named gwt-windows-xxx on Windows and gwt-linux-xxx on Linux, where xxx is the version number of the downloaded distribution. We will refer to the directory that contains the unzipped distribution as GWT_HOME. The GWT_HOME directory contains a samples folder with seven applications.

  2. 3. In order to ensure that the GWT is correctly installed, run the Hello sample application for your platform by executing the startup script for your platform (the executable scripts for Windows have the extension .cmd and the ones for Linux have the extension .sh).

    Execute the Hello-shell script for your platform. Here is a screenshot of the Hello application running successfully in the hosted GWT browser:

  • Click on the Click me button and you will get a dialog box as follows:

What Just Happened?

The GWT_HOME directory contains all the scripts, files, and libraries needed for GWT development, which are as follows:

  • doc: This directory contains the API documentation for the various GWT classes. The API documentation is provided in two formats—the Google custom format and the familiar javadoc format.

  • samples: A directory that contains the sample applications.

  • gwt-*.jar: These are the Java libraries that contain the GWT classes.

  • index.html: This file is used as Readme for the GWT. It also provides a starting point for the GWT documentation along with pointers to other sources of information.

  • gwt-ll.dll and swt-win32-3235.dll: These are Windows' shared libraries (Windows only).

  • libgwt-11.so, libswt-gtk-3235.so, libswt-mozilla17-profile-gcc3-gtk-3235.so, libswt-mozilla17-profile-gtk-3235.so, libswt-mozilla-gcc3-gtk-3235.so, libswt-mozilla-gtk-3235.so, and libswt-pi-gtk-3235.so: These are Linux shared libraries (Linux only).

  • applicationCreator: This is a Script file for creating a new application.

  • junitCreator: This is a Script file for creating a new JUnit test.

  • projectCreator: This is a Script file for creating a new project.

  • i18nCreator: This is a Script file for creating internationalization scripts.

When you executed Hello-shell.cmd, you started up the GWT development shell and provided the Hello.html file as a parameter to it. The development shell then launched a special hosted web browser and displayed the Hello.html file in it. The hosted web browser is an embedded SWT web browser that has hooks into the Java Virtual Machine (JVM). This makes it possible to debug the Java code for the application, using a Java development environment such as Eclipse.

Here is a screenshot of the development shell that starts up first:

There's More!

You can customize several of the options provided to the GWT development shell on startup. Run the development shell, from a command prompt, in the GWT_HOME directory to see the various options available:

@java -cp "gwt-user.jar;gwt-dev-windows.jar" com.google.gwt.dev. GWTShell help

You will see a screen similar to this one:

If you want to try out different settings, such as a different port numbers, you can modify the Hello-shell.cmd file to use these options.

The Linux version of GWT contains 32-bit SWT library bindings that are used by the hosted web browser. In order to run the samples or use the GWT hosted browser on a 64-bit platform such as AMD64, you need to do the following:

  • Use a 32-bit JDK with 32-bit binary compatibility enabled.

  • Set the environment variable LD_LIBRARY_PATH to the Mozilla directory in your GWT distribution, before starting the GWT shell.