Book Image

Google Web Toolkit 2 Application Development Cookbook

By : Shamsuddin Ahammad
Book Image

Google Web Toolkit 2 Application Development Cookbook

By: Shamsuddin Ahammad

Overview of this book

GWT 2 radically improves web experience for users by using existing Java tools to build no-compromise AJAX for any modern browser. It provides a solid platform so that other great libraries can be built on top of GWT. Creating web applications efficiently and making them impressive, however, is not as easy as it sounds. Writing web applications for multiple browsers can be quite tasking. In addition, building, reusing, and maintaining large JavaScript code bases and AJAX components can be difficult. GWT 2 Application Development Cookbook eases these burdens by allowing developers to quickly build and maintain complex yet highly efficient JavaScript front-end applications in the Java programming language . It tells you how to make web experience all the more thrilling and hassle free, using various tools along with GWT SDK.This book starts with developing an application from scratch. Right from creating the layout of the home page to home page elements including left and right sidebars, to placing tree like navigational menu, menu bars, tool bars, banners, footers are discussed with examples. You will see how to create forms using the Ext GWT library widgets and handle different types of events. Then you will move on to see how to design a database for sales processing systems and learn to create the database in MySQL with the help of easy–to-follow recipes. One of the interesting topics of this book is using JPA in GWT. Using the JPA object in GWT is a challenge. To use them perfectly, a mechanism to convert the JPA object into plain object and vice versa is required. You will see recipes to use entity classes, entity managers, and controller classes in GWT application. You will efficiently create reports with parameters, variables and subreports, and get the report output in both HTML and PDF format using real-world recipes. You will then learn to configure the GlassFish server to deploy a GWT application with database. Finally, learn how to trace speed and improve perfomance in web applications using tracing techniques.
Table of Contents (16 chapters)
Google Web Toolkit 2 Application Development Cookbook
Credits
About the Author
About the Reviewers
Preface
Index

Creating a GWT project in NetBeans


All the required tools and technologies are installed. Now, we will create the Java Web project using the Google Web Toolkit Framework in NetBeans.

Getting ready

Make sure that GWT and GlassFish are installed, the GlassFish server is added, and the GWT4NB plugin is installed in NetBeans.

How to do it...

  1. Start NetBeans.

  2. Go to File | New Project.

  3. Select Java Web from the Categories field, and Web Application from the Projects field, as shown in the following screenshot:

  4. Click on Next.

  5. Give Sales Processing System as the Project Name, browse the Project Location, and check Set as Main Project:

  6. Click on Next.

  7. Select GlassFish v3 from the Server list, and Java EE 6 Web from the Java EE Version.

  8. Set the Context Path, or leave it as suggested. It is the path to the "root directory" of a web application (called the context root), relative to the root of the web server namespace.

  9. Click on Next.

  10. Select Google Web Toolkit from the list of frameworks, browse for the GWT SDK Installation folder (such as C:\Program Files\gwt-2.0.3, or any other location where you have installed it), and name the GWT Module as com.packtpub.Main:

  11. Click on Finish on completion of the installation.

How it works...

After following the aforementioned steps, a NetBeans project structure with some sections containing the following files has been created:

  • Web Pages

    WEB-INF

    • sun-web.xml

    • web.xml

    welcomeGWT.html

  • Source Packages

    com.packtpub

    • Main.gwt.xml

    com.packtpub.client

    • MainEntryPoint

  • Libraries

    GWT2.0.3-gwt-user.jar

    gwt-dev.jar

    gwt-servlet.jar

    JDK1.6

    GlassFish v3

Directory and file structure

A directory and file structure is created, as shown in the following screenshot:

Running the project

A default code is given in the MainEntryPoint.java file. That's why, we can run the project to see a basic output. To run the project, right-click on Sales Processing System under Projects and then click on Run, as shown in the following screenshot:

The following events take place:

  1. GlassFish is started automatically, if it is not started yet. It will prompt the user for the username and password. Provide "admin" as the username and "adminadmin" as the password (or as we had set during the installation of GlassFish).

  2. The project is compiled by GWT Compiler.

  3. The project is deployed to the \Sales Processing System\build\web directory.

  4. The default browser is called with the URL http://localhost:8080/Sales_Processing_System/.

  5. The output is a button labeled Click me!. If the button is clicked, a label, Hello, GWT!!!, is hidden and displayed alternately: