About the Reviewer
Michael Smolyak started working with Java technologies in 1996. His experience as a developer, a technical lead and an architect covers all tiers of enterprise Java ecosystems. During his journey through Java, which started with Java 1.0.2, Michael has become Sun Certified Java Programmer, Developer and, most recently, Enterprise Architect. Michael holds a Master of Science degree in Management Information Systems and a Bachelor of Science degree in Applied Mathematics. Michael is currently working at DataSource, Inc on an exciting and powerful tool called Jetson, created to make development of robust and well-designed enterprise Java application a simple and straightforward task.
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.

GWT in Action



Author(s) Rober Hanson and Adam Tacy
Publisher Manning
PubDate 2007
Reviewer Michael Smolyak
Purchase and help Javalobby



Table of Contents




One Minute Review

Positives
  • Thorough coverage of the subject - addresses not only core GWT topics but also integration with other technologies,development methodologies and GWT inner workings
  • All topics are illustrated by code examples and visual representations of the GUI elements under construction
  • Builds a non-trivial application starting with basic features and adding to them as new subjects are covered
  • Intended for a wide audience by not assuming significant Java or JavaScript knowledge on the reader part
  • Written in well-articulated manner and well-organized
  • Makes the user understand that GWT is a fast-evolving product by describing both GWT 1.3 features and those slated for inclusion in 1.4
Negatives
  • The section comparing GWT with competing and complimentary technologies stopped at summarizing those technologies.It could have provided more information for developers to decide how to choose an appropriate technology.

Sections

Intent & Audience

The GWT in Action authors intended their creation for a wide variety of developers interested in building Web 2.0 applications. The journey through the book deals with a fair number of technologies. The book neither assumes your expertise in those technologies, nor does it serve as a primer for them. Instead the authors use detailed explanations and large number of examples to illustrate all the concepts introduced in the manual.

Familiarity with the technologies on which GWT relies will definitely help the reader to follow the topics and the accompanying examples. You do not have to be an expert in Java, but you need basic Java knowledge since the toolkit is Java-centric. You do not need to be proficient in Swing, but you will need appreciation of Swing-like concepts of GUI creation and event handling employed by GWT. You do not have to have years of experience with JavaScript to read the book, but since JavaScript is the underlying technology behind the code generated by GWT, some knowledge of the language and how it interacts with various browsers will make it much clearer what is happening behind the scenes.

The automated nature of the Google Web Toolkit (which generates a skeleton application for you and makes it trivial to load it in Eclipse IDE) assures that your development effort begins with a simple but fully functional Web application. It is very gratifying to have a working sample application 30 minutes into your acquaintance with the new technology. This lowers the barriers to entry to both the toolkit and the book written about it. That sample GWT application will be gracing your computer screen (assuming you follow the book's examples) after you are done with Chapter 1.

The gradual approach used by the authors starting with simple topics that are likely to be of interest to any GWT user and transitioning by the middle of the volume to the topics of greater complexity and more specialized interest (JSNI, GWT-RPS, integration with AJAX, code generation, etc.) assures that any reader interested in the subject of Google Web Toolkit will be able to find something accessible and useful in this book. It may be creation of GUI applications using only the existing widgets, or it may involve creation of new widgets, or development of server-side Java code with which the GWT application can interact, or integration of the GWT application with existing JavaScript or Ajax libraries. All those topics (and many more) receive an unhurried treatment on the pages of GWT in Action.

back to top Back to top

Relevance of material

The purpose of the Google Web Toolkit is to help Java developers leverage their knowledge of the language to build Web applications, for which previously a significant expertise in JavaScript and Ajax was required. Having much more experience with Java than JavaScript I was very appreciative of the level of productivity GWT would afford me in creation of Web application. As with any great tool, it makes things that should be simple simple and makes complex things possible.

The fact that the book is dedicated to a well-designed product that fills a significant void in the area of Web application development makes the book all the more readable and useful. The ability to leverage my Java and Swing skills in creating sophisticated Web applications was part of the satisfaction I received in reading the book. I also liked the fact that authors spend time on the issues many Web developers not coming from Java background may not be accustomed to such as unit testing and internationalization of Web applications, design patterns and architectural techniques.

The toolkit is designed for the users of different levels of sophistication in mind. The book captures this multifaceted nature of the GWT quite well by first laying out all the aspects with which one deals when building a GWT application and then methodically covering them in a logical and easy-to-understand manner. Whatever subjects were on the radar screen of the Google team, they are covered at some level in this book. And all those subjects, major and minor, are integrated in the Dashboard application, which is being developed as the book moves along.  The reader who needs to develop his own GWT application will definitely appreciate the chance to follow the development of the Dashboard application on his computer to get first-hand experience with Google Web Toolkit.

This volume was definitely intended for sequential perusal and not as a GWT reference guide.

back to top Back to top

Chapter highlights

Chapter 1 Introducing GWT. This chapter serves as a map for the entire book. Here the authors list all the technologies discussed in the rest of the book and dedicate a section to explaining how each technology (such as core GWT, its compiler, widgets, JRE emulation library, GWT-RPC, XML parser, to name a few) fits in the overall picture and how it is used. Next, the introductory chapter briefly raises us from the world of GWT and compares the toolkit with such competing (and complimentary) technologies as Swing, Echo2, JavaServer Faces and Ruby on Rails. Such a discussion is a good idea but here it is too short in my view to assist a reader in deciding which technology is more appropriate for his application. The introductory chapter concludes with the a hands-on exercise at the end of which a functional Tic-Tac-Toe game with is created by utilizing the combination of generated and hand-written code using such concepts as panels, buttons and event handlers.

Chapter 2 Creating the default application. The chapter starts with the discussion of the lifecycle of a typical GWT application, describing the purpose and the tools used in each stage. The bulk of the this chapter is dedicated to the first stage - creation of a default GWT application using the generation tools supplied by the toolkit. The purpose and usage of each tool (project creator for integrating application with Eclipse, application creator for generating Java packaging structure and basic Java and HTML source files, as well as the tools for internationalization and unit test generation) is well documented and illustrated with examples laying out the Dashboard application.

Chapter 3 Advancing to your own application. Chapter 2 presents a detailed explanation of the GWT application generation tools.  This chapter uses the generated GWT application and takes the first customization steps. First it lays out the road map for the complete Dashboard application (to be built by the end of the book) and then proceeds with custom changes including

  • laying the groundwork for internationalizing the application (Swedish is used as an alternative language)
  • constructing the HTML file to host the GWT application
  • adding logic to the application's entry point Java class to add a simple menu to the page
  • updating XML configuration file describing the Dashboard application module
  • adding styling to the application using CSS.

The remainder of the chapter addresses the deployment aspects of the application such as compiling, running it in the hosted mode, debugging and testing the application.

Chapter 4 Working with widgets. Next four chapters take the reader in the realm of GWT GUI components. Chapter 4 introduces those components, classified into widgets and panels. The important notion of widgets' dual existence (both as Java objects and browser DOM elements) is introduced in this chapter and reinforced throughout the chapters discussing GUI elements. The chapter walks the reader through the examples of all the standard GWT widgets and explains their inheritance model. Having done with brief but pithy widget overview, the authors introduce three ways of developing new widgets and proceed with the creation of new non-trivial menu item component for the Dashboard application.

Chapter 5 Working with panels. The toolkit's approach to laying out of the components is akin to that of Swing with a little twist. Instead of using a small number of containers (like panels) and large variety of Layout Managers, GWT combined the two notions. It comes with the large variety of panels, each with the predefined way of laying out the panels and widgets within it. The chapter introduces 5 groups of GWT panels and their inheritance hierarchy. Predictably, each type of panels is explored with examples illustrating their usage. Next the authors examine two ways of creating new panels (from scratch and by extending existing ones) and conclude the panel discussion with an example of a DashboardPanel extending GWT DialogBox and using a native JavaScript method for some of its functionality.

Chapter 6 Handling events. No discussion of a GUI toolkit can be complete without the exploration of event handling mechanism. This mechanism uses concepts of events, event listeners and event handlers so common in Java GUI programming. The difference between GWT and Java is that GWT code is executed in a web browser, which makes event handling browser dependent. The authors highlight the fact that GWT masks the differences between Internet Explorer's and other browser's event models (while explaining those differences). The first part of this chapter describes the low-level mechanics of sinking events, listening to events, previewing events and handling events at the individual widget level. Next the authors turn to the way the widgets allow their users to handle events at a higher level of abstraction by providing methods for registering listeners for the appropriate higher-level events (e.g., CellClicked for a table instead of a mouse click). The remainder of the chapter deals with handling of all types of supported browser events both those common to Java such as list change events, click events, keyboard and focus events, and those unique to GWT such as tab events, popup closing events, and tree events to name a few. The chapter concludes with the discussion of drag-and-drop implementation illustrated by a Dashboard example.

Chapter 7 Creating composite widgets. Having covered the basic widget building blocks of GWT, the authors are ready to show the reader how to construct custom component. They do it in the same logical manner transitioning the reader from simple composite widget examples to more complex components required for the Dashboard application. Before the building begins, the chapter presents a set of well-articulated steps for building composite widgets. The first widget, the chapter tackles, is a relatively simple editable label. Simple or not, the authors describe the sequence involved in creation of this widget in painstaking details checking off steps presented at the beginning of the chapter as they move along. This section is a great example of the effort put forth by the book authors to make it accessible to a wide range of Web developers. Their next example creates a more complex widget (using other composite widgets in the process), a color picker, using a more terse explanation style this time. The chapter concludes with the creation of a DashboardComposite class (by extension of a GWT Composite class, a type of a panel consisting of other panels) to handle focus events.

Chapter 8 Building JSNI components. JavaScript Native Interface is GWT's mechanism for embedding JavaScript in Java code. The chapters starts with the discussion of the reasons of why the developer may need to use JSNI (which is compared with using assembly language in a C application) cautioning the reader that it should be used as an approach of last resort. Using JSNI may add to the applications features (such as accessing browser functionality) not available in GWT. On the other hand JSNIcode may break browser portability GWT so hard tries to achieve. Having warned the reader, the authors proceed with explanation of the JSNI mechanism (which employs the Java native method machinery), the syntax for implementing native methods in JavaScript and the rules for data exchange between Java and Java Script and those for exception handling. Next the applications of JSNI are covered. Those include

  • communicating with the browser via JavaScript
  • exposing GWT application to legacy code through JavaScript API
  • exchanging information between GWT application using JavaScript variables
  • loading a JavaScript library through the module XML file
  • wrapping existing JavaScript libraries as GWT widgets

The last topic get detailed treatment in the remainder of the chapter. The authors explain the concepts and provide examples for wrapping existing Google JavaScript libraries, Google Video Search and Google AJAX Search in GWT Java classes.

Chapter 9 Modularizing an application. This chapter concludes the portion of the book dedicated to the core GWT technologies used on the client side. Here the authors explain the how GWT modules promote creation of well-designed applications and reusable GWT components. The chapter explains the thinking behind GWT modules and demonstrates with a comprehensive module example how

  • core GWT functionality, additional GWT packages and third party modules are included into the application module
  • external resources such as source files, icons, etc. are referenced and filtered
  • server-side resources such as servlets are pointed to
  • static and dynamic properties are handled
  • resources such as JavaScript and CSS are injected into application at runtime
  • application entry point is set.

back to top Back to top

Chapter 10 Communication with GWT-RPC. The first of the Advanced Techniques chapters deals with the subject of browser-to-server asynchronous communication using GWT remote procedure call mechanism. This chapter will be easier to understand to those with understanding of Java RPC concepts. The effort involved in implementing GWT-RPC is not complex (all the complexity is hidden behind the plumbing code) but involves a fair number of steps for defining interfaces and their implementations on the server and on the client. The chapter walks the user through the implementation of a simple service sending the status of server-side JVM to the GWT client. Each concept (asynchronous communications, supported data types, defining and implementing the service, generating client-side proxy object, creating a callback object, and, finally calling the service) is explained and illustrated with a code example. The chapter concludes with an overview of the entire project implementing the Server Status service and the simple client invoking the service.

Chapter 11 Examining client-side RPC architecture. This chapter uses a simple but well-designed GWT client for the Server Status service created in the previous chapter as an opportunity to present several architectural concepts. While constructing the client application, the chapter

  • reiterates GUI design techniques employed in earlier chapters
  • introduces Facade and Singleton patterns for encapsulating remote call in a separate component
  • discusses Command pattern used to construct a callback object (thus enhancing the original asynchronous callback handler utilizing an anonymous inner class)
  • realizes separation of concerns by creating an extensible callback class hierarchy with an abstract class to handle logging behavior

The next portion of the chapter is dedicated to the topic of polling techniques, which fall into two categories: server push and client pull. Both techniques are explained and explored by implementing pull and push solutions for the Server Status application. The chapter is concluded with the discussion of custom field serializers, which could be useful for serializing unusually complex data transfer objects.

Chapter 12 Classic AJAX and HTML forms. For the situations where GWT-RPC (which requires a Java application server) cannot be used GWT provides support for classic AJAX (on top of which GWT-RPC is build to provide a higher abstraction level). The chapter examines the basics of HTTP GET and POST methods after which it introduces RequestBuilder class also built on top of Ajax's XMLHTTPRequest but unlike GWT-RPC allowing to exchange only text-based data. The example of RequestBuilder usage involves reading an XML file from the server, parsing it and building a bookmark menu based on the file. The second part of this chapter explores the topic of HTML form support provided by FormPanel class. This class simplifies construction, submission, validation and processing responses for HTML forms. The authors describe various aspects of FormPanel usage including setting its target, using form controls, concluding the chapter with an example of using FileUpload control inside FormPanel for uploading files to the server.

Chapter 13 Achieving interoperability with JSON. Another solution for the applications not utilizing Java on the server side is to exchange data between the GWT client and the server using JSON, a lightweight, JavaScript-friendly message format. True to their form, the authors begin by introducing JavaScript Object Notation by examining basic and composite data objects. The introduction is followed by a JSON example, where GWT search client exchanges information with the server using JSON format. The Yahoo Search API-based server-side code is implemented in three different languages (Java, Perl and Ruby) to demonstrate flexibility of JSON as data exchange format.

Chapter 14 Automatically generating new code. Not only GWT uses code generation mechanism internally (e.g., for implementing internationalization or unit test creation), but it also exposes the generation API to the GWT user. This chapter explores the GWT code-generation mechanism enabling an application to generate code at runtime and use the generated code as part of the application. Examples showing how to generate a simple About menu implementation, which displays the selected widget's information, introduce the notions of Generator class, TypeOracle class providing information about a type, PropertyOracle class allowing to introspect type's properties, SourceWriter object used to write out generated code, classes representing introspection results (JMethod, JField) as well as the deferred binding approach allowing the application to use the newly-generated class at runtime.

Chapter 15 Changing applications based on GWT properties. GWT properties is a compile-time mechanism allowing the user to compile different classes into the GWT application based on certain conditions. The typical uses of properties include customizing code for different browsers and internationalizing applications. The chapter illustrates the former use with an example where two classes are developed, each for particular browser types, and the correct one is selected at compile time using <replace-with> XML tag in combination with "user.agent" property. The topic of internalization get detailed treatment in this chapter, which includes all the steps necessary to internationalize the application as well as the sample code demonstrating constant and properties files for English and Swedish locales and <extend-property> XML tags used to define supported locales. The chapter then discusses the topic of localization (extending default class behavior based on locales). Finally, the authors present an example showing the usage of user-defined properties for overriding class behavior based on intranet vs. Internet environment.

Chapter 16 Testing and deploying GWT applications. Not assuming unit testing concept knowledge on the part of the reader, the authors start the chapter with the introduction of JUnit framework and its usage patterns. Next, the chapter explains the unique features of GWT JUnit extensions such as unit test creator, tying tests to GWT modules, and facilities for testing in asynchronous mode. The remainder of the chapter is dedicated to the GWT client-side deployment topics such as overall project organization, removal of the files not used by the compiler, packaging JavaScript files as well as those for the server-side RPC modules such as deploying servlet-based RPC functionality in a Tomcat servlet container. The authors emphasize the differences between GWT version 1.3 and 1.4 wherever appropriate.

Chapter 17 Peeking into how GWT works. This chapter goes beyond the standard topics of GWT usage and explores how GWT does what it does. The under-the hood- subjects include

  • Content and purpose of files produced by the GWT compiler
  • Steps involved in loading GWT application for pre-1.4, 1.4 (standard) and cross-script applications
  • Examination of JavaScript code generated by compiling Java classes.

back to top Back to top

Rating

Hanson and Tacy have created a very readable and detailed introduction to the Google Web Toolkit. The thoroughness with which they designed examples to illustrate every concept dealt with in the book and the scope of the topics addressed in it makes GWT in Action a valuable addition to any Web developer library. Even if you are not planning to use this technology in your daily professional activities it is still a worthwhile endeavor to appreciate the ingenuity and understand the thinking of the Google team coming out with a product that makes it possible for the developers with server-side and desktop Java skills to build sophisticated Web applications.

Relevance
Readability
Overall

back to top Back to top

Resources

Google Web Toolkit

Google APIs

Ajax 

Yahoo! Search API 

JSON 

Purchase this book on Amazon and help Javalobby.