views:

1307

answers:

2
+3  Q: 

EXT GWT + java EE

Hello. My question is: what is the best way to send my jee 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.

regards

A: 

I'm not a specialist but it seems that people are using Gilead (which has a tutorial) + GWT + GXT to ease the process.

Pascal Thivent
+2  A: 

Hi Pecc, 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.

Dave Paroulek
Thank you for your input, and sorry for the late answer! I'm gonna dig myself into strategy #3 and check gilead out then decide which will be the best for me.
Pecc
Hello! I decided to try strategy #1 manually. However, I have some questions about it:
Pecc
- As gwt can't transfer entity beans via rpc, and BeanModelFactory can't be used in server-side gwt, it seems I have to first create a DTO class for every entity then send this DTO through rpc, and then convert it to BeanModel on the client side. Am I right?
Pecc
- What should I do with the relations between my entities when I'm converting them to DTOs?
Pecc
- Where do I send your thankyou-beers? :)
Pecc
Hi Pecc, what we ended up doing is creating a DTO for each Server-side POJO/Bean. Then we wrote conversion methods that convert server side objects to (and from) client side DTOs. Instead of using BeanModel, we just extended BaseModelData to create the client side DTOs and were able to pass those back and forth over rpc. The conversion methods handled the relationships as well. For example, sometimes we'd just create light DTOs, other times, we'd create deep copies depending on what we needed on the client side.
Dave Paroulek
It ended up being a bit redundant to have to create client side DTOs for each server side bean. So, if you find a better solution, please let me know! And always up for geeking out over beers if your ever near Washington, DC ;-)
Dave Paroulek