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();
if(phoneGap.isPhoneGapDevice()){
 requestTransport.setRequestUrl("http://yourserver/rf-servlet");
}
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.

2 comments:

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

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

    ReplyDelete