Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Some Recipes to Improve Your Google Web Toolkit Development

Experiences, tips and techniques to assist you in creating GWT Web applications.

  • Print
  • Feedback

Page 2 of 6

Now, my new tip is "divide et impera", a Latin phrase meaning, in our context, divide your application code from the beginning into three different parts for client-side code, RPC-related code, and server-side code, and create corresponding Eclipse projects to conquer your task. In doing so, you can make use of different Java language versions for your client and server part. I created the server part of the application (the servlet code) with Java 5, but in the following list you can replace Java 5 by Java 6, if you are using the Mustang release right now. Even if you are still using J2SE 1.4.2 on the server-side, such a division offers you more flexibility for the future and clearly separates your code ("separation of concerns"), without limiting your debugging actions in GWT hosted mode. If you have all sections in only one Eclipse project, you will need to be very disciplined, particularly on the server-side. Otherwise, compile or runtime problems will occur. My advice is to use a special naming convention that clearly identifies your distinct projects and that will make the deployment script easier. You can use an Eclipse working set named, e.g., GWT-<ModuleName> to include all three projects. Here, "ModuleName" is the name of the GWT module that identifies your web application; in my environment it was called "JUnit2MR", because the web application connected JUnit error messages to ClearQuest modification requests (MRs) by means of IBM Rational's new Java teamapi. Using a working set, everything you need is close together.

  • Client-Side code: Contains your UI related code that will be translated to JavaScript. Therefore you are limited to J2SE 1.4.2 and GWT runtime support. Enable Eclipse Java compiler settings and "Java Compiler Errors/Warnings" per project, adjust Java compliance level to "1.4" and source and class file compatibility to "1.4" (assuming you do not use JDK versions prior to 1.4). The name of this project is <ModuleName>-client, e.g., "JUnit2MR-client", and it depends on the <ModuleName>-rpc project in your build path settings. The package name is something like <com.company.project>.gwt.<ModuleName>.client.

  • RPC-related code: Contains your RPC related code that will be translated to JavaScript. This project follows the same guidelines as the client-side code project above. The project name is <ModuleName>-rpc, e.g., "JUnit2MR-rpc", and it depends on no other project. The package name is the same as for the <ModuleName>-client project. The RPC-project contains remote interfaces on the client-side, data transfer objects that are serialized by GWT during RPC, and global constant classes that will contain public constants used by client and server code (e.g., to handle input form data that is identified by unique names). Just a new remark on data containers: GWT forces your data containers used by RPC to implement the IsSerializable interface. The obvious problem with this approach is that on the server side you might have the same classes implement java.io.Serializable, which is not allowed by the GWT Java-to-JavaScript compiler. One possible solution is to have a JavaBean class on the server side implementing Serializable only, with exactly the same member variables as the data container used by RPC. Then you call PropertyUtils.copyProperties(serverBean, rpcDataContainer)or PropertyUtils.copyProperties(rpcDataContainer, serverBean) to copy your values back and forth. PropertyUtils is part of the Jakarta Commons BeanUtils project.

  • Print
  • Feedback

Resources

Google Web Toolkit home page

GWT Unofficial Wiki page

Introduction to GWT development: Ease AJAX development with the Google Web Toolkit

GWT add-on for debugging, developed by Mat Gessel.

GUI-based GWT testing with Selenium

For a good Ant script to deploy your GWT applications to Tomcat see: Google Web Toolkit: AJAX Buzz Meets Real World Development

Groovy Gant

To get the Gant script and the corresponding build.properties file for easy GWT deployment to Tomcat, download sample code.