I’m going to attempt to present an example of how to use the GWT (Google Web Toolkit) request factory and editor framework features.  My approach is to write a blog entry each time I make changes to my sample project.  This may become overly cumbersome, verbose, or boring, but it’s worth a shot!  I’ve created a Google code project that will contain the source code; the project name is: gwt-examples-by-andy, and you’re welcome to go browse it at code.google.com, and to download the code (this example project is named RequestFactoryExample1).  If you want to just import the project into Eclipse and run it (without following this tutorial) then you can follow these instructions:

Click to expand Eclipse import instructions

  1. From the Eclipse File menu select Import…
  2. In the Import dialog select the “Checkout Projects from SVN” from the SVN folder and then click Next (if there is no SVN folder then you’ll need to install Subclipse into Eclipse)
  3. In the “Checkout from SVN” dialog select “Create a new repository location” and then click Next
  4. Enter http://gwt-request-factory-editor-framework-example.googlecode.com/svn/trunk into the Url and then click Next
  5. Select the RequestFactoryExample1 folder and then click Finish
  6. In the Package Explorer right click on the RequestFactoryExample1 project and select Properties
  7. In the Properties dialog open the Google item and click on “Web Toolkit”
  8. Click in the “Use Google Web Toolkit” checkbox and then click OK
  9. In the Package Explorer right click on the RequestFactoryExample1 project and from the “Build Path” submenu select ‘Configure Build Path…”
  10. On the Source tab of the “Java Build Path” dialog click on the RequestFactoryExample1 entry and then click Remove
  11. Click on “Add Folder…” and select the “src” entry and then click OK
  12. Click on Browse… and highlight the /war/WEB-INF directory
  13. Click “Create New Folder…” and enter “classes” and then click OK and then click OK again
  14. On the “Java Build Path” dialog on the Source tab the default output folder should now be RequestFactoryExample1/war/WEB-INF/classes
  15. Go to the Libraries tab on the “Java Build Path” dialog
  16. Click “Add External JARs…” and add the Guava and Javax persistence jars and then click OK to close the “Java Build Path” dialog. Note: I sometimes find that it’s necessary to clean the project in Eclipse (alt-p followed by n) to clear some errors (this can be the case in various situations … when in doubt about an error I often try cleaning first!)
  17. In the Package Explorer right click on the RequestFactoryExample1 project and select Properties
  18. Under the “Java Compiler” entry click on the “Annotation Processing” entry
  19. Click to enable project specific settings (this will enable annotation processing)
  20. Click on the “Factory Path” entry under the “Annotation Processing” entry
  21. Click to enable project specific settings
  22. Click “Add External JARs…” and add the requestfactory-apt.jar file
  23. Right click on the RequestFactoryExample1 project and choose “Run As” -> “Web Application”

So let’s get started …

I’m using Eclipse, and I have the GWT plugin installed.  The first step is to create a new web application project, using the blue “g” icon on the Eclipse toolbar.  In the dialog that is displayed after clicking on the “New Web Application Project…” item I entered the following values:

  • Project name: RequestFactoryExample1
  • Package: org.greatlogic.rfexample1
  • Location: Create new project in workspace
  • Use Google Toolkit (default SDK, which is GWT 2.5 – 2.5.0.rc1 in my case)
  • Do not use Google App Engine
  • Do not generate project sample code

Next I created most (if not all) of the Java packages that will be needed, but this isn’t necessary at this stage … they could be created as needed, of course.  The packages are (under the org.greatlogic.rfexample1 package): client (i.e., org.greatlogic.rfexample1.client); client.event; client.model; client.view; client.view.interfaces; client.widget; server; server.model; and shared.

Under the org.greatlogic.rfexample1 package we need the “.gwt.xml” file, which in this case is named RFExample1.gwt.xml, and contains the following:

In the “war” folder there is the main HTML file and a “.css” file.  The RFExample1.css file is just an empty file (I don’t think I’m going to do any formatting in this project); the RFExample1.html file contains:

And now we can move to actual code, albeit code that doesn’t actually do anything.  I like to take things fairly slowly, and ensure that the program still runs after each incremental change; this can be a little tiring at times with GWT, because of the time that it takes to execute the program if a browser refresh is not sufficient.  But here goes … the first class is the main entry point class, of course, which is located in org.greatlogic.rfexample1.client.RFExample1.java:

Just a note about my program layout/format … methods are separated with a comment of dashes; the closing brace of each method has a comment that identifies the method; methods are sorted alphabetically within groupings of static methods, constructors, and ordinary methods; fields are sorted, and use an underscore prefix (except for UI fields); interface names begin with an “I” (e.g., IClientFactory).  There are other conventions that I follow; if any of these conventions annoy you then I’m sorry (somewhat)!

At this point the program should run (using the RequestFactoryExample1 selection from the “Run As…” button on the Eclipse toolbar), and you should be able to click on the link that is provided in the Development Mode view.

I will be using the following additional JAR files for this project: Google Guava; and the Java Persistence API … you should add these to the project build path.

In the next installment I’ll define the server side entity and create the UI interface to support the entity.

Part 2

Leave a Reply