Weekly GWT Links for 12/23

December 23rd, 2007 - Written by in News, Using GWT

Here are some of the more interesting links from the past week.

  • Interview with Dion Almaer – Didier Girard of onGWT.com has posted a really interesting interview he did with Dion Almaer at this years Javapolis. Dion works at Google on the Google Gears project and is also the founder of Ajaxian.
  • – A Facebook application written in GWT. Numbrosia is a number/slider puzzle game.
  • – The Rocket GWT framework is “a collection of widgets, and other useful abstractions for authoring GWT applications.” This latest release contains some GWT serialization improvements.
  • GWT RPC Presentation – Links to the slides and notes of Rob Jellinghaus’ presentation on GWT RPC at this years GWT conference.
  • GWT Testing with Groovy – Tutorial on using the Groovy programming language to do GWT unit testing.
  • GWT Vector Graphics Library – Interesting looking demo. Unfortunately, the library itself doesn’t seem to be publicly available at the moment.
  • Gwittir for GWT – Gwittir is a project whose goal is “to provide a set of code generators, scaffolding, utilities, and a basic MVC framework for use with Google Web Toolkit based applications.” This article shows how to use its Bean binding and Animation mechanisms.

Have a Merry Christmas everyone!

No Comments Stumble it!

GWT Serialization Tutorial

December 20th, 2007 - Written by in Using GWT

The guys over at developerlife have been putting up new GWT tutorials at a prolific pace. Their newest tutorial demonstrates how to use the GWT Serialization mechanism in a Contact List application.

Check out some of their previous tutorials as well:

For a list of other good GWT tutorials, you can also check out the Resources page on this site. Feel free to leave a comment and suggest your favorites.

1 Comment Stumble it!

Getting started with GWT and Google Gears

December 17th, 2007 - Written by in Using GWT

Google Gears is a library that enables your web applications to work offline. Currently it consists of three modules: LocalServer for caching and serving up your web app resources (ie. html, javascript, images), a SQLite Database for storing offline data, and a WorkerPool for performing asynchronous operations. My GWT application, a free Sudoku game called GSudokr seemed to be a good candidate for testing out the LocalServer module of Gears as it doesn’t have any complicated requirements like synchronizing back to a server. After reading all the documentation, I was able to get everything working in less than a day. In this short tutorial, I will walk you through the steps I took to get GSudokr working offline using Gears.

Installing

Download the following:

On OS X, Google Gears is installed as a Firefox extension. On Windows, it’s actually a standalone installer which enables Gears support for both IE and Firefox. The gwt-google-apis project is a library for GWT that support the various Google APIs. Lucky for us, the first API they decided to support was Google Gears!

Add gwt-google-apis.jar to your project and in your GWT module xml file, you’ll need to add the line:


Working with the API

The basic class for serving up locally cached pages is called LocalServer. In your application you can instantiate the class like this.

try {
    localServer = new LocalServer();
 }
 catch (GearsException e) {
    // Will throw GearsException if Gears is not installed
 }

If the user does not have Gears installed than LocalServer cannot be instantiated and will throw a GearsException. So be aware of this situation and display an appropriate message for your users.

LocalServer is used to create resource stores, which are a collection of URLs to cache. There are two types of supported resource stores, ResourceStore and ManagedResourceStore. With ResourceStore, you pass in the name of the urls to cache inside your application using the captureURLs() method. On the other hand, ManagedResourceStore, lets you list these urls in an external manifest file. Since GWT generates its files dynamically, ManagedResourceStore is the only approach that will work. To save the effort of trying to input all the urls by hand into the manifest, I wrote a simple php script which I run after compiling my app, that will generate the appropriate manifest. Take a look at it as an example. [generateManifest.php]

The code to create the resource store, open it and set the manifest url is straightforward. I took the code straight from the sample ManagedResourceStoreDemo in the gwt-google-api distribution. The interesting part of the code is the checkForUpdate() method.

managedResourceStore.checkForUpdate();
new Timer() {
   public void run() {
      switch (managedResourceStore.getUpdateStatus()) {
         case ManagedResourceStore.UPDATE_OK:
            statusLabel.setText("Ready for offline access");
            break;
         case ManagedResourceStore.UPDATE_CHECKING:
         case ManagedResourceStore.UPDATE_DOWNLOADING:
            schedule(500);
            break;
         case ManagedResourceStore.UPDATE_FAILED:
             statusLabel.setText("Unable to go offline");
             break;
         }
      }
}.schedule(500);

ManagedResourceStore’s checkForUpdate() method tells Gears to asynchronously check your manifest file and start downloading the resources specified in it. A timer is then created which checks the update status on the store to see if your files have been downloaded and cached. You can use the various status codes to inform the user in your UI about what’s going on. When you receive the UPDATE_OK code, your app is ready to go offline. To test this, use the Work Offline function in your browser (Firefox: File > Work Offline). Make sure to clear your cache, and try to access your application using your regular url.

As you can see, it is quite simple to get your GWT applications working offline using LocalServer. Keep in mind that Gears is still in beta and the user experience still leaves something to be desired, especially to the casual user. Still, it’s quite cool to able to add offline capabilities to your web application with a minimal amount of effort.

References

6 Comments Stumble it!

« Previous Entries