Skip to content

EXT GWT + java EE

My question is: what is the best way to send my Java EE annotated entity beans’ data to the clientside to use it in a grid for example? Surely I could make the BaseModel-extended client models for each entity manually, but I wonder what could be the best-practice here. I need a step-by-step tutorial if possible.

Answer

I’ve been using ext-gwt (gxt) for about a year now and feel your pain!

From what I’ve learned so far, it seems that there are 3 strategies for transfering beans back and forth between client and server:

Here’s an overview of each strategy:

  1. Create a client pojo/bean that extends BaseModel for each server side object bean/pojo/entity bean.
  2. Share pojo/bean’s between client and server
  3. Convert server side pojo/beans into json before sending to client and then use Javascript (json) objects on client side.

Of course, there are trade offs to each.

Strategy #1 integrates nicely into gxt. You can use gxt’s built in stores and bindings. This is the strategy I’ve used on a production application and it has worked, but I’ve found it tedious to duplicate beans on client and server. Personally, I’ve also found that extjs’s (and gxt’s) store/binding mechanism can be overly complicated and difficult to extend for corner cases.

Strategy #2: This is the strategy I’ll most likely use on my next gxt project. The downside is that you have to do you’re own form and grid binding in gxt on the client. But the upside is that you can share all your beans/pojos. Here’s a quick overview of implementation details:

In your server side src tree, add a .gwt.xml file into the root package that contains your server pojo/bean classes. For example: I created this file named “gwt-models.gwt.xml” under com.daveparoulek.gwt.server.models

<module rename-to='gwt-models'>
    <inherits name='com.google.gwt.user.User' />
    <source path="client" />
</module>

In the example above, the beans are actually located inside com.daveparoulek.gwt.server.models.client.

Once you have that setup, you can configure your client gwt project to include the src code inside com.daveparoulek.gwt.server.models by adding a “inherit” tag to your gwt client project’s gwt.xml file for example:

<inherits name="com.daveparoulek.gwt.server.models" />

Strategy #3: After watching a few talks from google on gwt, this seems to be their preferred way to deal with objects on client side. Although, this leads to creating a json overlay type for each server side pojo/bean. This also doesn’t fit perfectly into gxt world. Click here for a pretty good intro to this concept.