You skipped to finish reading the tutorial.
Direct quote from tutorial :
RequestBuilder code is replaced by a call to the getJson method. So, you no longer need the following code in the refreshWatchList method:
RequestBuilder builder = new RequestBuilder (RequestBuilder.GET, url);
try {
Request request = builder.sendRequest (null, new RequestCallback () {
public void onError (Request request, Throwable exception) {
displayError ("Couldn't retrieve JSON");
}
public void onResponseReceived (Request request, Response response) {
if (200 == response.getStatusCode ()) {
updateTable (asArrayOfStockData (response.getText ()));
} else {
displayError ("Couldn't retrieve JSON (" + response.getStatusText ()
+ ")");
}
}
});
} catch (RequestException e) {
displayError ("Couldn't retrieve JSON");
}
In general, what you have, and it should be replaced by the JSNI function specified in the tutorial, is a few lines below:
/ **
* Make call to remote server.
* /
public native static void getJson (int requestId, String url,
StockWatcher handler) / * - {
var callback = "callback" + requestId;
// [1] Create a script element.
var script = document.createElement ("script");
script.setAttribute ("src", url + callback);
script.setAttribute ("type", "text / javascript");
// [2] Define the callback function on the window object.
window [callback] = function (jsonObj) {
// [3]
handler.@com.google.gwt.sample.stockwatcher.client.StockWatcher :: handleJsonResponse (Lcom / google / gwt / core / client / JavaScriptObject;) (jsonObj);
window [callback + "done"] = true;
}
...
source share