about this book

Welcome to GWT in Practice. This book is intended to serve as a practical field guide for developers working with the Google Web Toolkit. While it includes some introductory information, it is not a complete introduction to all the classes and libraries included with GWT. It is, however, a guide to working around common issues developers encounter when building GWT applications, and to working with other Java EE technologies.

When getting started with GWT, there are a lot of things that will seem alien to traditional web developers in the Java world. This begins with GWT’s tooling—a specialized version of Tomcat for debugging and testing your Ajax applications—and continues into the design approach—an expression of the Model View Controller (MVC) pattern more akin to desktop application development than the web frameworks you may be familiar with. Hopefully this book will smooth the glide path for you as you move into development with GWT.

GWT in Practice also looks at working with technologies you may be familiar with, but that have different usage patterns in the GWT world. These include using the Java Persistence API with Hibernate or TopLink, working with build tools, testing, and continuous integration. These are at the core of modern enterprise application development but can be problematic for new GWT developers. We’ll give you what you need to integrate GWT applications into your enterprise development environment.

Who should read this book

Ajax development brings advantages to both users and application providers; GWT brings the advantages of Ajax and the benefits of Java to developers. This book will be of most help to Java developers coming to GWT’s style of Ajax development.

While you don’t need to understand everything in this book to get value from it, you should have some basic experience with web development in a Java EE environment and some experience working with Java application servers. Obviously, a working knowledge of HTML and CSS is important, as is a basic understanding of the browser DOM. Some experience with JavaScript or Ajax is also beneficial.

We have made an effort to cover as many tools in our examples as possible. Whether you use Eclipse, NetBeans, or IntelliJ IDEA to edit code, and Ant or Maven to build your projects, you will find at least one chapter that deals with your tools. Of course, this means many of the chapters will include discussions of tools that are not your own. We expect you to be familiar enough with your tooling to work around the parts you don’t care about specifically.

You should find this book to be helpful and a good ongoing reference while you are developing your applications. If your needs are task-specific, chances are good that at least one or two chapters cover what you are looking for. However, if you have limited experience with web technologies in general, we recommend you start with GWT in Action, available from Manning as well.

Roadmap

This book is divided into three parts. Part 1 is a quick introduction to the “GWT way,” which includes tools and concepts the rest of the book relies upon. Part 2 includes a series of practical examples laid out in a problem, solution, and discussion format. Part 3 dives into a larger hands-on sample application that puts all of the GWT pieces together.

In chapter 1 we take a brief historical tour and explore the roots of Ajax itself, and then address why it’s important and how GWT can help. We also cover the basic tools and terminology involved in GWT.

Chapter 2 starts with an exclusively client-side example that reinforces some of the basic GWT tenets and stresses a few new points, such as the fact that in GWT a lot more than the view exists on the client. This is where GWT differs from many other web toolkits—it allows a true Model View Controller (MVC) architectural approach to be used in a browser-based application.

From there the logical step is to create a full-featured client with server resources. In chapter 3 we use GWT Remote Procedure Calls (RPCs), demonstrate what serializable types are, and show how talking to servers works with GWT RPC. We also cover some of the details of the GWT hosted mode development shell, which uses an embedded version of Apache Tomcat.

Those first three chapters form the foundation of the book. We then move into part 2. In chapter 4, we go a bit deeper into what a canonical GWT application involves, including data binding and using the Java Persistence API (JPA) with GWT to persist data in a database.

Chapter 5 concentrates on talking to servers using mechanisms other than GWT RPC. Here we discuss JavaScript-to-Java details, the usage of JavaScript Object Notation (JSON), browser security, and the same-origin policy. This is also where we utilize Representational State Transfer (REST) and XML over HTTP. We conclude by running a Simple Object Access Protocol (SOAP) example from a GWT client (using Flash), and incorporating applets. This chapter runs the gamut in terms of ways to expose GWT clients to data, and it demonstrates the flexibility you have when working with GWT in general.

Chapter 6 then goes on to take a close look at the GWT JavaScript Native Interface (JSNI) mechanism, and the GWT-API-Interop library. Both of these are used to integrate existing JavaScript libraries with GWT.

In chapter 7 we focus on building, packaging, and deploying GWT applications with both client- and server-side components. Here we discuss creating and sharing GWT projects as libraries and creating deployable Web Application Archive (WAR) files. This is also where we first touch on using an automated build with GWT, and we cover the use of both Ant and Maven.

We put the automated build technique to further use in chapter 8, where we cover continuous integration and testing. Testing has some unique aspects in GWT, and some complications involving performance, code coverage, and remote testing, all of which are addressed here.

Then we move on to the third part of the book, “Dirty Hands.” As the title of this part implies, this is where we roll up our sleeves and crank out some non-trivial example applications. In chapter 9 we cover the use of Data Transfer Objects (DTOs) as part of the GWT application model. Here we discuss the integration of server-side libraries such as Spring, and we build out an Ajax-enabled administrative CRUD (Create Read Update Delete) interface for a bookstore.

In chapter 10 we continue the sample application from chapter 9 and add the user-facing storefront. We further discuss security and the concept of roles, and then we add some eye candy by creating a drag-and-drop system for GWT. We also discuss JSNI special effects.

In chapter 11 we get into another sample application, this time a screen-sharing example that utilizes the Comet push technique. In this example, we deal with application state using the GWT history mechanism, and we also cope with state on the server side.

Finally, we conclude the book with two appendices that provide valuable reference information. Appendix A describes many impressive third-party GWT applications or libraries that you can use to enhance or extend your own applications. Appendix B is a general reference that includes GWT tools and options, definitions for GWT module descriptor and host page elements, a list of emulated JRE classes available with GWT, a description of GWT serializable types, and a list of common user interface widgets and the event handling they support.

Code conventions

In the text, the names of classes, keywords, interfaces, XML elements, code, and other code-related terms are presented in a monospace font. In longer code examples, some lines have been reformatted to fit within the available space on the page. Additionally, some lines of code were so long that they simply couldn’t be represented and we have truncated them with the [...] signifier and noted them.

Code annotations are used in place of inline comments in the code. These highlight important concepts or areas of the code. Some annotations appear with numbered bullets that are referenced later in the text. The original source code also contains additional comments you might find of value.

Code downloads

All the code referenced in this book is available for download from www.manning.com/GWTinPractice or www.manning.com/cooper. We expect that if you are working through the book as a practical exercise, you will download and have this code available, as not all the code needed to run the projects is included in the text of the book.

Once you have unzipped the example source distribution, you will find it organized by chapter. Each chapter’s folder contains a readme.txt file that provides specific setup instructions or considerations for working with that code. There is also a top-level file that provides a detailed overview of the project layout conventions.

The example code works for Mac, Windows, and Linux users. To get started, you should set up two environment variables: JAVA_HOME (if you don’t have it set by default), and GWT_HOME. These can be set using the set command on Windows, or export on Mac OS X or Linux.

Author Online

The purchase of GWT in Practice includes free access to a private forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and other users. You can access and subscribe to the forum at www.manning.com/GWTinPractice. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct in the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions, lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.