Google Web Toolkit (GWT)

I went through an example to try out GWT. The GWT website GWT has some very good documentation. I went through the stock watcher example and built it step by step myself. Made a few changes on the way, such as putting the whole thing in a TabPanel.

I believe Java UI frameworks, that produce web code (html), are a great alternative to DIY HTML/Javascript libraries. Everytime I look at AJAX web frameworks and libraries, I think many of us are missing the point. Focus on building the application and not tinker with so many frameworks. I think frameworks like GWT will provide a strong alternative in the years to come. Toolset (IDE) support will make or break these frameworks.

After implementing the example, I was amazed at the ease with which I could implement AJAX functionality. In this case the UI periodically polls the backend for stock price changes and updates the section of the page. The code was...

            // setup timer to refresh list automatically

            Timer refreshTimer = new Timer() {

                  public void run() {

                        refreshWatchList();

                  }

            };

            refreshTimer.scheduleRepeating(REFRESH_INTERVAL);


The refreshWatchList method is shown below...

      private void refreshWatchList() {

            // lazy initialization of service proxy

            if (stockPriceSvc == null) {

                  stockPriceSvc = GWT.create(StockPriceService.class);

            }

 

            AsyncCallback<StockPrice[]> callback = new AsyncCallback<StockPrice[]>() {

                  public void onFailure(Throwable caught) {

                        // do something with errors

                  }

 

                  public void onSuccess(StockPrice[] result) {

                        updateTable(result);

                  }

            };

 

            // make the call to the stock price service

            stockPriceSvc.getPrices(stocks.toArray(new String[0]), callback);

      }


Its so obvious what the above code does. Well almost obvious. There are some GWT specific weird stuff you need to do, but thats a small price to pay. Here is an image of the output screen...




The price and change columns periodically update themselves (without refreshing the whole page of course). Here is my complete Eclipse project if you want to try it out. Download StockWatcher

 del.icio.us  Stumbleupon  Technorati  Digg 

 

What did you think of this article?




Trackbacks
  • Trackbacks are closed for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.