Wednesday, July 4, 2007

More on the GWT and Topic Maps

This morning I found what could be the ultimate web development environment for GWT in Eclipse. This plugin (developed by an open source group called Cypal), integrates with the existing web tools project for Eclipse allowing easy integration of old web projects with new ones. Check it out here: Cypal Studio

And for those of you looking to get started searching topic maps built in XTM (or LTM - Linear Topic Maps), check out tolog. It is an efficient query language reminiscent of prolog and SQL.

There's some great stuff out there
--Shaun

Thursday, June 7, 2007

Welcome and the GWT

First of all, welcome to whoever views this blog. I hope we can develop some insights on Enterprise Software Development together.

My first port of call on this blog will be the
Google Web Toolkit (GWT). A "quick and dirty" way to implement AJAX and dynamic RPC with Java backend. In short, the
GWT allows any developer to code in plain old java objects that extend a very specific (yet adaptable) libr
ary, provided by our friends at google. The library consists of classes and interfaces for building user interfaces composed of HTML elements, implementing an RPC system (using AJAX), providing internalisation, and performing remote and local JUnit testing.

Building User Interfaces

Three types of classes are used to build user interfaces with GWT, namely:
  • A point of entry class (that implements EntryPoint): acts as a control class and initialises and manages the user interface. This class must implement the method onModuleLoad() which initialises the various widgets.
  • Widgets: are java objects that represent the various HTML user controls. Some are standard HTML form controls, such as Button, while others make use of a complex combination of HTML tags and controls.
  • Panels: act as container widgets for holding and positioning other widgets.
While the implementation involves the use of a few unique methods, building user interfaces is simple and resembles the conventional Swing/AWT frame construction. However, it is much easier to user and manipulate than Swing/AWT in my opinion. In addition, the style of every widget is described in a CSS file. The setStyleName() and removeStyleName() methods for each widget allow a new CSS class name to be associated with that widget. The normal naming style for a widget class is .projectName-widgetName .

Remote Procedure Calls (RPC)

Google has put together a useful and highly automated RPC system that passes real, serialised Java object. In reality, the underlying RPC system makes use of AJAX calls (using the XMLHTTPRequest Javascript object). In the eyes of the developer, the entire system is constructed using Java classes and interfaces. The following diagram is reproduced from the web toolkit development guide (and is also a link to it):


Considering the above diagram, the YourService interface contains the method headers for methods involved in RPC. The YourServiceImpl implements this class on the server-side and provides the necessary functionality requested in the RPC call. It must also implement the RemoteServiceServlet class provide in the GWT library, and not the traditional HTTPServlet. As stated in the development guide, RemoteServiceServlet automatically handles serialization and invoking the intended method in your service implementation.

On the client side, the related YourServiceAsync interface duplicates the method headers provided in the YourService interface, taking into account two major differences. Firstly, none of the methods have a return type (i.e. void), and secondly, they contain an extra parameter of type AsyncCallback that represents the return value or exception that results from the RPC. The GWT compiler provides the implementation for this interface automatically and seamlessly.

All parameters passed to the RPC methods must be serializable. Because the GWT converts the client-side objects to javascipt, there are some additional restrictions and considerations on serializable type to consider here.

Rather than reinventing the wheel, I am merely going to redirect you to the example of how to code the client RPC call in the development guide. The example is very simple and walks through both the construction of the objects necessary for the call and the handling of the result of the call.

One final note: the backend used beyond the RemoteServiceServlet can take any form and is completely independent of the presentation.

Internationalisation

Google provides a number of techniques for internationalisation using constant and message property files. There also more complex forms and variations of these available to the developer. In there most basic form, constant files provide a way to load fixed local parameters and locale information. Message files allow parameters to be inserted amongst the property values. This is a very basic outline of internationalisation tools available in the GWT. For more details, refer to this section of the developer's guide.

JUnit Testing

JUnit test classes are created for modules rather than individual classes. Modules will be explained in the next section, but suffice it to say here that JUnit testing can be performed in both hosted mode (before compilation to Javascript) and in web mode (after compilation and possibly running on other more robust J2EE server implementations). Debugging launch configurations can even be created for Eclipse.

Modules

GWT projects/units are configured and expressed in XML files called modules. As stated in the developer's guide, a module bundles together all the configuration settings that your GWT project needs, namely
  • Inherited modules
  • An entry point application class name; these are optional, although any module referred to in HTML must have at least one entry-point class specified
  • Source path entries
  • Public path entries
  • Deferred binding rules, including property providers and class generators
Please refer to this section for more info on the Module format. Stylesheets are also attached to a project in the Module XML file for describing the look and feel of widgets. Please see the module format link for information about how to do this.

Project and Application Generation

GWT projects are created using the command line application projectCreator in the GWT directory. A similar application is used to create applications, call applicationCreator. An eclipse parameter (-eclipse) can be attached in both cases to create Eclipse compatible projects and applications that can be run and debugged from within the Eclipse IDE. The applicationCreator also generates scripts for compiling the GWT application to Javascript and launching it in hosted mode.

Final Thoughts

The GWT is an extremely efficient ways to build AJAX compatible web UIs that appear (for all intents and purposes) to work as if they were a standard RPC system built using Swing and AWT components for the front-end. Google have discovered a way to maintain an existing UI design paradigm without sacrificing modern AJAX speed, functionality and, to be frank, beauty. In addition, they have ensured that the presentation elements of an enterprise application are completely separate and independent of the logic and data elements. Any J2EE backend is compatible with the GWT front-end, making service delivery flexible and efficient. Forrapid AJAX development without browser compatibility issues, testing nightmares and a high learning curve, give the GWT a try.

That's it for now...
Shaun

Portions of this page are reproduced from or are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 2.5 Attribution License. This post refers specifically and in detail to the Google Web Toolkit Developer Guide.