views:

437

answers:

4

Hi

I'm having a problem. I would like to create Document object, and I would like to have a user property with com.google.appengine.api.users.User type (on GAE's docs site, they said we should use this object instead of email address or something else, because this object probably will be enchanced to be unique). But now the object can't be compiled by GWT, because I don't have the source for that object. How can I resolve the problem?

I was searching for documents about DTOs, but I realized that maybe that's not the best pattern I should use.

What do you recommend?

Very thanks for your help!

Regards, Bálint Kriván

+2  A: 

There is a lot of debate about whether you should be able to reuse objects from the server on the client. However, the reuse rarely works out well in real applications so I generally recommend creating pure java objects that you copy your data into to send to the client. This allows you to tailor the data to what you need on the client and avoids pitfalls where you accidently send sensitive information over the wire.

So in this case, I would recommend that you create a separate object to send over the wire. BTW if you have the AppEngine SDK for Java (http://code.google.com/appengine/downloads.html), it includes a demo application that I did (sticky) that demonstrates this technique.

Kelly Norton
Hi!Thanks for your answer!I've checked your source, it looks promising, but I realized that you're using directly the Datastore API. Isn't it too implementation-detailed usage?Maybe if I would use JDO, it would be a little bit more abstract (If I would deploy my application on other service than GAE), but It bothers me a little bit, that I have "duplication", of course I gain more control on what information I really send over.I will think about it, but probably I will choose DTOs.
Bálint Kriván
A: 

Hi, I had the same question, your answer is interesting, but i am always sad to copy twice a data... Plus, when your dao gets the data, you will have to parse all the results to copy them to the pure java object, isn't it? It seems to be a heavy operation. What's your opinion about those question?

Mahyar Sepehr
+1  A: 

this question also addresses the issue: It links to a semi workable solution for automatically making your persistent objects gwt-rpc compatible.

Peter Recore
+3  A: 

Hi, to avoid DTOs for objects with com.google.appengine.api.users.User inside you can probably use the work from http://www.resmarksystems.com/code/ He has build wrappers for the Core GAE data types (Key, Text, ShortBlob, Blob, Link, User). I've tested it with datastore.Text and it worked well.

Thanks for guiding me. Maybe that's I was looking for :)Btw, I'm still not sure to use or not to use DTOs ;)
Bálint Kriván