This is a small walkthrough of a simple login screen written with the Google Web Toolkit on the front end, and Groovy and Hibernate on the back end. The entire source code can be found here. For the purposes of brevity we will look at only parts of the code. An IntelliJ 7 project file is included, but the required libraries are not.
The class client.Test implements a GWT Interface named com.google.gwt.core.client, and that is where the application starts on the client side. client. client.Test creates widgets from the GWT for the username text and field, the password text and field, and the login button. The login makes use of GWT RPC which talks to a Servlet in a JSP Container such as Tomcat or Jetty. The call to the server for the valid login is “asychronous”, meaning the client will not wait for the request to complete. The login button will remain disabled until it is explicitly enabled by our code or it is removed from the DOM tree by our code. The client will be notified of the server response via a com.google.gwt.user.client.rpc.AsyncCallback that gets attached to the request. This interface includes the methods onFailure and onSuccess, a failure callback may mean that the server is down or the client has lost connection or some other type of communication error. Once the client receives a response from the server, an alert window is displayed that states the status of the login. If there is a valid user in your database and the server side is working correctly you will see a “Login Successful” message and the login button will be re-enabled. In a normal application we would remove the login widgets and begin loading the home page widgets at this point on the client side.
The server side simply waits for a request from the client and uses Hibernate to query a database for the username/password combination. The use of Groovy shows how the typical verbosity of Java code is lessened with dynamic typing and closures and a scripting-language like syntax. Here is User.groovy, the User data object:
Here is UserDAO.groovy, the class responsible for querying the database:
If you browse the code you may be thinking that this is too many files for just a simple login screen. And you would be right, but, there are some benefits to this simple application over a JSF/Java/JDBC application.
- With GWT you get “Ajax” for free, no need to hand code JavaScript or use IceFaces or RichFaces or some other JSF Ajax library. GWT helps to break out of HTML form based programming which can be limiting.
- If you have developed with any thick client toolkit like Swing , SWT, MFC, Windows Forms, etc, you will appreciate the simplicity of sending asynchronous requests out and waiting to make the GUI changes via callback methods. Every well performing Swing application has to do this already, it has to start a new Thread, and maybe even lower that thread’s priority, to free the AWT event dispatch thread so the user can still perceive good performance from the application.
- Third, thanks to Hibernate and a simple configuration file in the WebRoot/WEB-INF folder, your application is database agnostic, to the degree that Hibernate supports of course. That means you can easily change the configuration file to point to an Oracle, SQL Server, MySQL, Postgres database server and expect the application to work.
- With GWT internationalization is simple, and even simpler with IntelliJ 7, which keeps the internationalization properties file and interface in sync.
- Groovy has made the server side code less verbose and therefore easier to read and faster to write and test than it’s Java counterpart could ever imagine.
- The client side code can be unit tested with Java, and can be de-obfuscated if the generated JavaScript needs debugging.
- Seventh, you are still able to use CSS to style the GWT widgets, so you don’t have to abandon your CSS skills when using GWT.
- GWT provides a shell mode so you don’t have to deploy an app to a JSP Container and start it, you can develop and debug the application from the command line or IDE integration. If you really need another technology on the server side you can drop the Groovy/Hibernate/Tomcat idea and use JSON to talk to PHP, Perl CGI, ASP.NET, etc.


How would you suggest sharing/remoting domain classes like User with GWT and Hibernate? JSON is clumsy. DTO is duplication. Gilead does not support Groovy domain classes.
Thanks,
Don Ruby
[Translate]