Generating Enterprise Class GWT Applications for Spring
Exploring the Customer GWT Model
Let’s take a closer look at one of the generated GWT modules for the Customer domain object. This module contains all of the boiler plate code that you would normally write to build a GWT application using the standards and best practices listed above.
Top GWT Module Packages
The first two packages in the Customer module are the gwt.customer and gwt.customer.client packages.
The gwt.customer package simply contains the GWT Module.xml definition file for the Customer module.
The gwt.customer.client module contains the DTO Object representation for Customer, an ID class for uniquely identifying a Customer, the Service and Async Service interfaces, and the CSS and I18N messages that are used by the Customer UI.
The Actions package
The actions package contains the Actions or Commands that can be passed back and forth to the Server to accomplish specific tasks. There are actions for loading, storing, and deleting customers as well as Actions for managing relationships TO customer. This is an important point because the Actions for managing relationships are generic such that you can use the same Action to manage the relationship between SalesRep and Customer, and Product and Customer. This approach also allows us to make the screens for managing relationships to Customer more OO. You will also notice that for each Action, there is the Action, a Response Object, and a Action”ed” classes. This approach helps to encapsulate the code to pass these actions and receive their asynchronous callbacks. We will take a look at a specific example further on.
The Events package
The events package declares a set of Events that can be listened for on the EventBus. The UI Components that are generated automatically register themselves to listen on the Event bus for certain events in order to deal with changes to the data. If you want to hang some new behavior off the side of a Customer being deleted for example, all you have to do is add a CustomerDeleted handler to the Event bus and your code will be notified.
The Server package
The Server package contains the code that is executed on the server side of the application. This code can contain references to classes that cannot be compiled by GWT and allows us to integrate with the Service , DAO, and Domain layers. If you choose not to scaffold the Service and DAO layers in the Wizard, the Service Implementation will be generated with stubbed out methods that you can later implement to call your own back end implementation. The GWTCustomerUtil class is a utility class that can do the conversion from your DTO Objects coming in from the GWT client back to the persistent version of those Objects on the Server, and back. The default implementation takes care of merging the Data and using the DAO and Service layers to handle persistence. This approach does not require any 3rd party projects that attempt to map JPA to GWT for example and leaves the developer open to implement other approaches to persistence.
The Components package
The components package contains the GWT UI Components that are designed to provide the developer with course grained java objects that can be used to build UI’s that work with Customers in this case. These components generally use UIBinder, are prewired to work with the EventBus, Actions and Events that are generated in the other packages, and they allow the implementing Actions to be dependency injected into the Presenter in order to allow them to remain loosely coupled and testable. There are paginated tables for both “listing” objects in a table and a table for “selecting” objects with only a few columns as you may see in a “Picker”. There are general Edit widgets which provide you with Form based input and display of the Objects fields and properties. There are Relationship widgets for managing relationships TO customer, both Single or (One) sided relationships, or (Many) sided relationships. There are also Dialogs for your convenience for Editing or Picking customers. The tables are all specific implementations of the PagingScrollTable from the GWT Incubator project.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)