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

Mapping entity classes and DTOs


In RPC, the client will send and receive DTOs, but the server needs pure JPA objects to be used by the Entity Manager. That's why, we need to transform from DTO to JPA entity class and vice versa. In this recipe, we will learn how to map the entity class and DTO.

Getting ready

Create the entity and DTO classes.

How to do it...

  1. Open the Branch entity class and define a constructor with a parameter of type BranchDTO. The constructor gets the properties from the DTO and sets them in its own properties:

    public Branch(BranchDTO branchDTO)
    {
    setBranchId(branchDTO.getBranchId());
    setName(branchDTO.getName());
    setLocation(branchDTO.getLocation());
    }
    
  2. This constructor will be used to create the Branch entity class object from the BranchDTO object.

  3. In the same way, the BranchDTO object is constructed from the entity class object, but in this case, the constructor is not defined. Instead, it is done where it is required to construct DTO from the entity class.

There's more...