View Full Version : proxy question

25 Jun 2010, 9:18 AM
Hi Sven

I'm currently using script tag proxy to get data along with GWT jsonpReqest class because I dont really know how to handle errors in gxt's proxy method, and manipulating and playing with data after it's retrieved.

How can i do this?

25 Jun 2010, 9:20 AM
I dont understand what you mean, please post a testcase that implements EntryPoint and shows what you have. Also post what you want it to be.

25 Jun 2010, 9:25 AM
This is basic structure of GWT JsonpRequst implemntation Im using
there is async callback that allows onError case, and onSuccess

is there similar functionality in gxt? specifically using script tag proxy

import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
import com.google.gwt.user.client.rpc.InvocationException;
import project.client.model.JSONData; // json data overlay

public class Sandbox extends EntryPoint {

private static LayoutContainer lc;

public void onModuleLoad() {
super.onRender(parent, index);
setLayout(new VBoxLayout());


lc.add(new Label("make test request"));


private void initialize() {
lc = this;
lc.setLayoutData(new VBoxLayoutData(new Margins(10)));

private void test() {
String url = GWT.getHostPageBaseURL() + "testdata/test.json";
JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
jsonp.requestObject(url, new AsyncCallback<JSONData>() {
public void onFailure(Throwable caught) {
lc.add(new Label("test request failed"));
System.out.println("Error: " + caught);
try {
throw caught;
} catch (IncompatibleRemoteServiceException e) {
// this client is not compatible with the server;
// cleanup and refresh the browser
} catch (InvocationException e) {
// the call didn't complete cleanly
} catch (Throwable e) {
// last resort -- a very unexpected exception

public void onSuccess(JSONData data) {
lc.add(new Label("test request made"));

public static void show(JSONData data) {
lc.add(new Label("parsing data"));
int id = data.getId();
String method = data.getMethod();
JSONObject result = data.getResult();
JSONObject error = data.getError();

lc.add(new Label("data parsed"));
Label lb1 = new Label("ID : " + id);
Label lb2 = new Label("Method " + method);
Label lb3 = new Label("Result :" + result.toString());
Label lb4 = new Label("error : " + error);

lc.add(new Label("print data"));
lc.add(new Label("print data done"));


25 Jun 2010, 9:26 AM
There is, if you use it together with a Loader, than the loader fires a Load and a LoadException event

25 Jun 2010, 9:28 AM
you mean something like this?

public class Jsonp {

public static void asyncCall(
final String url, // URL to retrieve JSON result
ModelType type, // ModelType to define JSON format
final EventType successEvent, // Event needs to be fired after a successful communication
final EventType failureEvent, // Event needs to be fired after a failed communication
int timeout) { // Timeout in seconds

ScriptTagProxy proxy = new ScriptTagProxy(url);
JsonPagingLoadResultReader reader = new JsonPagingLoadResultReader(type);
final PagingLoader loader = new BasePagingLoader(proxy, reader);
final ListStore store = new ListStore(loader);

final Timer t = new Timer() {
public void run() {
Dispatcher.forwardEvent(failureEvent, "ERROR: timeout");

loader.addListener(Loader.Load, new Listener() {
public void handleEvent(BaseEvent be) {
int count = store.getCount();
if (count == 0) {
Dispatcher.forwardEvent(failureEvent, "Zero result(s)");
} else
Dispatcher.forwardEvent(successEvent, store);

loader.addListener(Loader.LoadException, new Listener() {
public void handleEvent(BaseEvent be) {
Dispatcher.forwardEvent(failureEvent, "Exception: " + ((LoadEvent)be).exception.toString());

25 Jun 2010, 9:32 AM
initially, I used general event update, load, update error, update success, etc...
but then I had hard time passing out the event to class that made request.

so adding the event type made it passing the event data easier. but it seemed to require lots of events..
pretty much 2~4 events for form, or classes that make request

any suggestion?