ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Working with the Google Web Toolkit

by Robert Cooper
05/31/2006
SEO + Web Traffic = Money

The Google Web Toolkit (GWT) was rolled out for JavaOne 2006 at an innocuously titled session. Due to what I assume was a timing miscommunication, the Google Blog scooped the presentation, but the impact was no less felt.

GWT is, in essence, a JavaScript generator. The interesting thing is what this JavaScript is generated from: Java. GWT takes Java code written against a special API and converts it into browser-runnable Ajax code. If that weren't enough to make it cool, it also includes a test harness (see Figure 1) that will execute the Java code inline with a test browser, allowing you to step-through debug (see Figure 2), profile and unit test your Ajax front end in your favorite IDE or at the command line.

Google Web Toolkit console window
Figure 1. GWT includes a console window with hierarchical logging.

Debugging in NetBeans
Figure 2. Java execution in the test browser allows for step-through debugging of code.

As they say, "But wait! There's more!" GWT also includes a basic RPC framework for making calls back to your server application in the form of a servlet. The RemoteServiceServlet allows you to implement service methods on an implementation and expose these to your generated Ajax application. This is done by simply adding new public methods to the servlet, and the GWT will handle serialization and deserialization to and from the client. How much would you pay for a framework like this? Don't answer yet!

GWT also includes a set of core DOM mapped classes and layouts that are more familiar to desktop application developers, such as the dock panel and horizontal panel. Prefabbed widgets such as PopupPanel for context popups, DialogBox for popup blocker friendly dialogs, and StackPanel for Outlook-bar style displays. There is also a URI and History management system for maintaining a bookmarkable and "back buttonable" state through your application.

Getting Started

GWT is really just an executable Java application with some hooks into Tomcat and either Mozilla or MSIE under Linux and Windows, respectively (sorry Mac users, you are out of luck for now). When you download the GWT, it comes with several sample projects, including "KitchenSink," the GWT equivalent of SwingSet. You can run the batch file in the samples/KitchenSink directory to see it run. Two things will pop up: the GWT server monitor application and browser window where you can see the application run. Executing java com.google.gwt.dev.GWTShell --help with your platform's *dev.jar and gwt-user.jar will show you the options available:

Google Web Toolkit 1.0.20
GWTShell [-port port-number] [-noserver] [-logLevel level] 
    [-gen dir] [-out dir] [-style style] [-notHeadless] [url]

where 
  -port         Runs an embedded Tomcat instance on the specified
                port (defaults to 8888)
  -noserver     Prevents the embedded Tomcat server from running,
                even if a port is specified
  -logLevel     The level of logging detail: ERROR, WARN, INFO, 
                TRACE, DEBUG, SPAM, or ALL
  -gen          The directory into which generated files will be
                written for review
  -out          The directory to write output files into 
                (defaults to current)
  -style        Script output style: OBF[USCATED], PRETTY, 
                or DETAILED (defaults to OBF)
  -notHeadless  Causes the log window and browser windows to be
                displayed.  Useful for debugging.
and 
  url           Automatically launches the specified URL

Google includes an applicationCreator script that will generate a set of batch files, scaffolding classes, and directories for a new GWT project. For our purposes here, however we are going to bypass this and start from scratch. First you will want the GWT Maven plugin installed. You can install this by unzipping the plugin project and typing maven plugin:install-now. Also, you will want to copy the gwt-user.jar to ~/.maven/repository/com.google.gwt/jars/ manually. Since this JAR needs to be included in your final WAR file, it needs to be registered as a dependency in the Maven POM file.

Search Engine Optimization

Essential Reading

Search Engine Optimization
Building Traffic and Making Money with SEO
By Harold Davis

SEO--short for Search Engine Optimization--is the art, craft, and science of driving web traffic to web sites.

Web traffic is food, drink, and oxygen--in short, life itself--to any web-based business. Whether your web site depends on broad, general traffic, or high-quality, targeted traffic, this PDF has the tools and information you need to draw more traffic to your site. You'll learn how to effectively use PageRank (and Google itself); how to get listed, get links, and get syndicated; SEO best practices; and much more.

When you approach SEO, you must take some time to understand the characteristics of the traffic that you need to drive your business. Then go out and use the techniques explained in this PDF to grab some traffic--and bring life to your business.


Read Online--Safari
Search this book on Safari:
 

Code Fragments only

Pages: 1, 2, 3, 4, 5

Next Pagearrow