views:

1244

answers:

2

Hi,

My application is logically divided into server, which contain my Grails domain objects and controllers; and client, where I have my Ext GWT classes that build all the UI pages.

For UI requests, I am using an AJAX call to a controller method that returns, for instance, a list of domain objects as a JSON structure.

Following the DRY principle, I wouldn't like to "serialize" the domain data to a JSON string on the server then de-serialize it on the client to another structure - I'd like to take advantage of the Domain object I already have, this I don't have to change multiple places when I add, change or remove a new field.

Question is: is that a good way to go?

If yes, how would be the best way to make .groovy domain objects available on the "client-side" Ext GWT Java classes?

If no, why is it bad and what would you advice instead?

+1  A: 

There isnt a good way - you need a java object that is GWT serializable. The only real solution that I can see is to write a plugin (or add to the GWT plugin) a way to autogenerate the data transfer object, perhaps using annotations in a grails domain object.

A similar method is being used to autogenerate the RPCAsync interfaces in the gwt plugin - see GwtGrailsPlugin.groovy in the gwt plugin directory, line 133 or so is the start.

You could hook into that (or just modify that file directly, probably easier) and insert some code to generate the data transfer files. An added benefit could be that you could granularize the data transfer object so that private data (like passwords!) dont get transferred.

Chii
Thanks Chii, awesome ideas. I'll look into it!
kolrie
if you are attempting this, may i suggest you post up the modifications for others to see? it might be helpful. I m actually thinking of doing this in one of my project - i just havent gotten to it yet! When i do i'll post it up somewhere - probably in the grails gwt plugin jira.
Chii
A: 

Alternatively, you can send your data to the clientside as either json or xml. you can create a REST api for your serverside.

Joshua Kamau