Sunday, January 30, 2011

SmartGWT and GWT RPC Integration

I am currently finishing my Capstone project for my MSE at Carroll University. While the application I am writing itself doesn't have a lot of twists in it, I decided to use this opportunity to experiment with some different technologies.  I'm using GWT, SmartGWT, and Hibernate in the application.  I've used Hibernate and GWT pretty extensively in my professional career, but the twists I've added for this development are to configure Hibernate using the JPA standard, and to use GWT Designer for mockups.  I've already posted about my experiences with GWT Designer.

I haven't really used SmartGWT before.  My experience has been with the ExtGWT library, which I loved.  I chose to use SmartGWT on this build because it is fully LGPL, while Ext is dual licensed.  While working with SmartGWT I've found some things that I was not expecting.

One of the selling points of SmartGWT is that it has built in support for 'Data Binding' with Tables and the like.  This is done through DataSource objects.  The problem is, the published DataSource implementations don't work with GWT RPC. And the DataSource base class has dozens of methods (Just take a look at the JavaDoc).  It really isn't clear how to define your own custom data source, or the work it will take to do so.  This was a sticking point for me because I really like the GWT RPC mechanism, and I had already come up with a nice security model, which I posted about here.

It took a while, but I finally found a post about integrating GWT RPC on the SmartClient Forums.  The post is a bit dated and says you need to compile from source, but that is not the case.  The version of SmartGWT I am using, 2.4 already has the clientCustom flag built in.  The developer who posted this also supplied 5 files, Including a GwtRpcDataSource abstract class, and a sample implementation.  The class comments well what you need to do to implement your datasource. With this setup, a new GWT data source can be defined by implementing 4 methods.  

I hope this post helps others find the solution much faster than I was able to.


  1. Hi Can you post some sample code. Also did you implement any paging?

  2. I don't have paging in the system yet, but I will implement it. The paging parameters are set in the DSRequest object from SmartGWT, so you just have to integrate that with your server side code. I would post code examples, but the Forum post has a complete working example posted. Its not my code and I don't want to take credit for it: