Monday, April 30, 2012

GWT RequestFactory and Phonegap

After being asked a lot of times if RequestFactory works with Phonegap, I finally decided to write my answer down.

The short answer is yes, but you need to do one thing.

If you are writing a mobile website with mgwt it works out of the box, of course!
This only applies if you are building apps with gwt-phonegap and RequestFactory as your RPC mechanism.

By default RequestFactory knows the url of your server (the script got loaded from there), but if your script runs inside an app on a phone, it does not know your server. 
To fix this you need to set the RequestTransport for your Factory and give it the url, which would look something like this:

EmployeeRequestFactory factory = GWT.create(EmployeeRequestFactory.class);

DefaultRequestTransport requestTransport = new DefaultRequestTransport();
factory.initialize(eventBus, requestTransport);

This is actually all you need to do. This is much easier if you compare it to GWT RPC and Phonegap.
Because it is much harder to configure GWT RPC for Phonegap there are utility methods in GWT Phonegap.


  1. This comment has been removed by a blog administrator.

  2. regards,
    I use GWT and GWT-phonegap in a project.
    An example of this post, I've tried and does not work.

  3. You can feel free to examine this iphone spy app and test in on your own device.