The client-server architecture has undergone a vast change over a short period of time. Earlier, each application had a different client software, with the software serving as the UI. This software had to be installed individually on every client, and needed to be updated every time we made changes to the application. We moved from that to the web era and deploying applications on the Internet, and then Internet enabled us to use the omnipresent web browser for accessing our applications from anywhere. This was a sea change, but we still had issues of performance and applications not having the same feel or responsiveness as desktop applications. Enter AJAX, and now we can build web pages that can rival a desktop application in responsiveness and nifty looks. AJAX underpins the current trend in developing applications for the Internet known as Web 2.0. In order to build Ajaxified applications you need to know HTML, XML, and JavaScript at the very least.
The Google Web Toolkit (GWT) makes it even easier to design an AJAX application using just the Java programming language. It is an open-source Java development framework and its best feature is that we don't have to worry too much about incompatibilities between web browsers and platforms. In GWT, we write the code in Java and then GWT converts it into browser-compliant JavaScript and HTML. This helps a lot, because we can stop worrying about modular programming. It provides a programming framework that is similar to that used by developers building Java applications using one of the GUI toolkits such as Swing, AWT, or SWT. GWT provides all the common user-interface widgets, listeners to react to events happening in the widgets, and ways to combine them into more complex widgets to do things that the GWT team may never have envisioned! Moreover, it makes reusing chunks of program easy. This greatly reduces the number of different technologies that you will need to master. If you know Java, then you can use your favorite IDE (we use Eclipse in this book) to write and debug an AJAX GWT application in Java. Yes, that means you can actually put breakpoints in your code and debug seamlessly from the client side to the server side. You can deploy your applications in any servlet container, create and run unit tests, and essentially develop GWT applications like any Java application. So start reading this book, fire up Eclipse, and enter the wonderful world of AJAX and GWT programming!
In this book, we will start with downloading and installing GWT and walk through the creation, testing, debugging, and deployment of GWT applications. We will be creating a lot of highly interactive and fun user interfaces. We will also customize widgets and use JSNI to integrate GWT with other libraries such as Rico and Moo.fx. We will also learn to create our own custom widgets, and create a calendar and a weather widget. We will explore the I18N and XML support in GWT, create unit tests, and finally learn how to deploy GWT applications to a servlet container such as Tomcat. This book uses a typical task-based pattern, where we first show how to implement a task and then explain its working.
Chapter 1 introduces GWT, the download and installation of GWT, and running its sample application.
Chapter 2 deals with creation of a new GWT application from scratch, and using the Eclipse IDE with GWT projects, creating a new AJAX Random Quotes application, and running the new application.
Chapter 3 deals with an introduction to and overview of GWT asynchronous services, and creating a prime number service and a geocoder service.
Chapter 4 deals with using GWT to build simple interactive user interfaces. The samples included in this chapter are live search, auto fillable forms, sortable tables, dynamic lists, and a flickr-style editable label.
Chapter 5 introduces some of the more advanced features of GWT to build more complex user interfaces. The samples included in this chapter are pageable tables, editable tree nodes, a simple log spy, sticky notes, and a jigsaw puzzle.
Chapter 6 includes an introduction to JavaScript Native Interface (JSNI) and using it to wrap third-party Javascript libraries like Moo.fx
and Rico
. It also includes using the gwt-widgets project and its support for the Script.aculo.us
effects.
Chapter 7 deals with creating custom GWT widgets. The samples included in this chapter are a calendar widget and a weather widget.
Chapter 8 concerns itself with creating and running unit tests for GWT services and applications.
Chapter 9 sees us using Internationalization (I18N) and client-side XML support in GWT.
Chapter 10 includes the deployment of GWT applications using both Ant and Eclipse.
GWT needs Java SDK installed. It can be downloaded from the following site: http://java.sun.com/javase/downloads/. The safest version is to use with GWT is Java 1.4.2, as they are completely compatible with each other. Different versions of GWT are available for different operating systems, so you can use your favorite OS without any hassles.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
There are three styles for code. Code words in text are shown as follows: "The GWT_HOME
directory contains a samples
folder with seven applications."
A block of code will be set as follows:
public interface PrimesService extends RemoteService { public boolean isPrimeNumber(int numberToVerify); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:
calendarPanel.add(calendarGrid); calendarPanel.add(todayButton);
Any command-line input and output is written as follows:
applicationCreator.cmd -out <directory location>\GWTBook\HelloGWT com.packtpub.gwtbook.HelloGWT.client.HelloGWT
New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "Click on the Click me button and you will get this window with your message."
Note
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply drop an email to <[email protected]>
, making sure to mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <[email protected]>
.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Visit http://www.packtpub.com/support, and select this book from the list of titles to download any example code or extra resources for this book. The files available for download will then be displayed.
The downloadable files contain instructions on how to use them.
Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the Submit Errata link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata are added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
You can contact us at <[email protected]>
if you are having a problem with some aspect of the book, and we will do our best to address it.