GWT in Practice
Robert Cooper and Charles Collins
  • April 2008
  • ISBN 9781933988290
  • 376 pages
  • printed in black & white

A true hands-on manual for GWT.

Edmon Begoli, Oak Ridge National Laboratory

GWT in Practice is an example-driven, code-rich book designed for web developers who have already learned the basics of GWT. After a quick review of GWT fundamentals, GWT in Practice presents scores of handy, reusable solutions to the problems you face when you need to move beyond "Hello World" and "proof of concept" applications. This book skips the theory and looks at the way things really work when you're building projects in GWT.

GWT in Practice shows you where GWT fits into the Enterprise Java developer's toolset. Written by expert authors Robert Cooper and Charlie Collins, this book combines sharp insight with hard-won experience. Readers will find thorough coverage of all aspects of GWT development from the basic GWT concepts and essentials to in-depth and complete real world example applications. If you know the basics and are ready to get your hands dirty, then you need this book.

Table of Contents show full



about this book

about the cover illustration

Part 1 Getting Started

1. Introducing GWT

1.1. Why GWT

1.1.1. History

1.1.2. Why Ajax matters

1.1.3. Leveraging the web

1.1.4. Tooling and testing

1.1.5. A single code base

1.1.6. Limitations

1.2. What GWT includes

1.2.1. GWT compiler

1.2.2. User Interface layer

1.2.3. Remote Procedure Calls

1.2.4. Additional utilities

1.2.5. GWT shell

1.3. GWT basics

1.3.1. Modules and inheritance

1.3.2. Host pages

1.3.3. Entry point classes

1.4. Working with the GWT shell

1.4.1. The logging console

1.4.2. The hosted mode browser

1.5. Understanding the GWT compiler

1.5.1. JavaScript output style

1.5.2. Additional compiler nuances

1.5.3. The compiler lifecycle

1.6. Summary

2. A New Kind of Client

2.1. Basic project structure and components

2.1.1. Generating a project

2.1.2. The standard directory structure

2.1.3. GWT starting point files

2.1.4. Host pages

2.1.5. Modules

2.1.6. Entry points

2.2. Design patterns and GWT

2.2.1. MVC and GWT

2.2.2. Creating a widget

2.2.3. Communicating by observing events

2.2.4. Operator strategy

2.2.5. Controlling the action

2.3. Styling a GWT component

2.3.1. Providing a CSS file

2.3.2. Connecting style names with Java

2.4. Running a completed project

2.4.1. Hosted mode and the GWT shell

2.4.2. Web mode and the GWT compiler

2.5. Summary

3. Communicating with the Server

3.1. Making GWT Remote Procedure Calls

3.1.1. Starting the HelloServer project

3.1.2. Defining GWT serializable data

3.1.3. Creating RPC services

3.1.4. Expanding on RemoteServiceServlet

3.1.5. Calling the server from the client

3.1.6. Troubleshooting server communication

3.2. The development server—Tomcat Lite

3.2.1. The web.xml file

3.2.2. The context.xml file

3.3. Using an external development server

3.4. Summary

Part 2 Task-specific Issues

4. Core Application Structure

4.1. Building a model

4.2. Building view components

4.2.1. Extending widgets

4.2.2. Extending composite

4.2.3. Binding to the model with events

4.3. The controller and service

4.3.1. Creating a simple controller

4.3.2. JPA-enabling the model

4.3.3. Creating a JPA-enabled service

4.4. Summary

5. Other Techniques for Talking to Servers

5.1. Web development methods and security

5.1.1. Dealing with browser security

5.1.2. Understanding XMLHttpRequest

5.1.3. Coding asynchronously

5.1.4. Developing GWT applications in NetBeans

5.2. Enabling REST and POX communications

5.2.1. Making basic HTTP requests with GWT

5.2.2. Making advanced HTTP requests with GWT

5.2.3. Working with XML

5.3. Understanding Java-to-JavaScript interaction

5.3.1. Using GWT JavaDoc annotations to serialize collections

5.3.2. Using JSON

5.4. Creating a cross-domain SOAP client with Flash

5.4.1. Using Flash as a SOAP client

5.4.2. Setting a Flash security context

5.4.3. Drawbacks and caveats

5.5. Incorporating applets with GWT

5.5.1. Using Java as a SOAP client

5.5.2. Signing JARs for security bypass

5.6. Streaming to the browser with Comet

5.7. Summary

6. Integrating Legacy and Third-Party Ajax Libraries

6.1. A closer look at JSNI

6.1.1. JSNI basics revisited

6.1.2. Potential JSNI pitfalls

6.1.3. Configuring IntelliJ IDEA

6.2. Wrapping JavaScript libraries

6.2.1. Creating a JavaScript module

6.2.2. Creating wrapper classes

6.2.3. Using the wrapped packages

6.3. Managing GWT-JavaScript interaction

6.3.1. Maintaining lookups

6.3.2. Daisy-chaining Java listeners into JavaScript closures

6.3.3. Maintaining listeners in Java

6.3.4. Conversion between Java and JavaScript

6.4. Wrapping JavaScript with GWT-API-Interop

6.5. Summary

7. Building, Packaging, and Deploying

7.1. Packaging GWT modules

7.1.1. Building and packaging modules

7.1.2. Sharing modules

7.2. Building and deploying applications

7.2.1. The client side

7.2.2. The server side

7.2.3. Manually building a WAR file

7.3. Automating the build

7.3.1. Extending the Ant build

7.3.2. Using Maven

7.4. Managing Tomcat Lite from the build

7.5. Summary

8. Testing and Continuous Integration

8.1. GWT testing

8.1.1. Knowing what to test

8.1.2. How GWT testing works

8.1.3. Testing gotchas

8.1.4. Basic GWT tests

8.1.5. Testing outside of GWT

8.2. Advanced testing concepts

8.2.1. Benchmarking

8.2.2. Remote testing

8.2.3. Code coverage

8.2.4. Coverage in an automated build

8.3. Continuous integration

8.3.1. Adding a GWT project to Hudson

8.4. Summary

Part 3 Fully Formed Applications

9. Java Enterprise Reinvented

9.1. Constructing two models

9.2. Mapping to DTOs

9.3. Wiring applications with Spring

9.4. Constructing the client application

9.4.1. The controller and global model

9.4.2. The basic CRUD wrapper

9.4.3. The BookEdit widget

9.5. Summary

10. Building the Storefront

10.1. Securing GWT applications

10.2. Building a drag-and-drop system

10.2.1. Enabling dragging

10.2.2. Handling drops

10.3. JSNI special effects

10.4. Summary

11. Managing Application State

11.1. Overview of the sample application

11.2. Creating a basic messaging service

11.3. Handling messages on the client and server

11.3.1. Messages and CometEvents

11.3.2. Streaming messages to the client

11.3.3. Receiving images

11.4. Recording and playing back conversations

11.4.1. Capturing changes to the model layer

11.5. Dealing with state on the server side

11.6. Adding a UI and cleaning up

11.6.1. Displaying events

11.6.2. Sending events

11.6.3. Cleaning up

11.7. Summary

Appendix A: Notable GWT Projects

Appendix B: Quick Reference


About the Technology

If you're a web developer, you already know that you can use Ajax to add rich, user-friendly, dynamic features to your applications. With the Google Web Toolkit (GWT), a new Ajax tool from Google that automatically converts Java to JavaScript, you can build Ajax applications using the Java language. GWT lets you focus on application design and functionality, rather than on browser differences, and allows you to re-use code throughout the layers of your applications.

About the book

The first part of the book is a rapid introduction to the GWT methodology. All of the basics of GWT development are covered in this portion, including a client side standalone application and basic server side communications using the GWT Remote Procedure Call (RPC) and object serialization mechanism.

The second part of the book then delves into several practical examples which further demonstrate core aspects of the toolkit. These include:

  • Using the GWT APIs
  • GWT methods for communicating with servers
  • Event-driven programming approach used with the toolkit
  • Support for JavaScript Object Notation (JSON)
  • Native JavaScript integration with the JSNI
  • Packaging and deployment of GWT applications
  • Testing with JUnit.

The book concludes by presenting several larger GWT applications including drag and drop support for UI elements, data binding, processing streaming data, handling application state, automated builds, and continuous integration.

Along the way GWT in Practice covers many additional facets of working with the toolkit. Various development tools are used throughout the book, including Eclipse, NetBeans, IDEA, Ant, Maven, and, of course, the old fashioned command line. The book also addresses integrating GWT with existing applications and services along with enterprise and team development.

What's inside

  • How to create and customize widgets
  • The ins and outs of RPC
  • Packaging and building with Maven and Ant
  • Using the Java Persistence API with GWT
  • Effective internationalization

About the authors

Robert Cooper is a JEE developer with over 15 years of web development experience. He is a the creator of several open source projects, including the FeedPod text-to-speech podcasting system, the GWT-Maven plugins for supporting Maven based builds for the Google Web Toolkit, and the Gwittir GWT framework. He is also a contributor to other open source projects such as the ROME RSS/Atom API for Podcasting and MediaRSS.

Charlie Collins is a JEE developer with over 10 years of experience. He has been involved with enterprise development, architecture, and general programming using several languages and technologies, with a focus on Java and the web tier. He has been an ardent open source supporter for many years and has contributed documentation and patches for various open source projects. Charlie is currently a contributor to the GWT-Maven project, the Android-Maven project, the Gwittir GWT framework, and the FeedPod text-to-speech podcasting system.

eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Cooper and Collins live and breathe GWT - their code is spotless.

Andrew Grothe, Triware Technologies Inc.

Expertly explains the genius of this technology - a real gift.

Peter Pavlovich, Kronos Inc.

The more complex your project, the more critical is this information.

Ara Abrahamian, NSI ltd

The perfect guide to GWT in the real world.

Devon Hillard,