Question

First of all,

many thanks to Craig for the excellent answer below which I found very useful when searching my original issue... ref: GWT Simple RPC use case problem : Code included

Building on this solution, how does one overcome the (seemingly GWT limitation) where if i leave my persistable object in /shared folder as Craig suggests... and annotate it as GWT tutorials suggest...

@PersistenceCapable
public class Employee {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

GWT is seemingly unable to deal with / import the com.google.appengine.datastore.key on the client side?

I have seen a few ugly hacks...but nothing elegant.

Any suggestions welcome, Thanks

Was it helpful?

Solution

Unfortunately, App Engine's Key class (and others) are not GWT-compatible. This means that you have to retrieve an object from the datastore, then translate it into a GWT-compatible POJO to send over GWT-RPC to the client.

I suggest looking into using the objectify framework for App Engine. Not only is it a much simpler interface into the datastore, but the persistent objects it uses are GWT-compatible, so you can send them over GWT-RPC to your client.

OTHER TIPS

You can use the Key class in GWT code by adding these additional jar files:

http://www.resmarksystems.com/code/

  • appengine-utils-client-1.0.jar
  • appengine-utils-server-1.0.jar

This basically gives the GWT compiler a GWT-friendly version of the Key and other AppEngine classes. (like Text, Blob and User..)

To use:

  • Add the appengine-utils-client-1.0.jar anywhere in your build path.
  • Put the appengine-utils-server-1.0.jar to your WEB-INF/lib folder.

In your GWT module add the following:

<inherits name="com.resmarksystems.AppEngineDataTypes"/>

If you don't need the Key object for something your key can be a Long or String which are easily serializable and thus work with standard GWT-RPC.

Datastore keys

I think Google has just released a GWT library called requestfactory for this use-case. This is the link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top