public abstract class JSONRequestCallback<T extends JavaScriptObject>
implements RequestCallback {
private final native T evalJSON(String jsonText) /*-{
return eval(jsonText);
}-*/;
@Override
public void onResponseReceived(Request request, Response response) {
String responseText = response.getText();
onResponseReceived(request, evalJSON(responseText));
}
/**
* Handle a JSON payload response.
*
* @param request
* the original request object.
* @param response
* the JSON response marshalled as a JavaScript object.
*/
public abstract void onResponseReceived(Request request, T response);
}
new JSONRequestCallback<JsArray<SomeModelObject>>() {
@Override
public void onError(Request request, Throwable exception) {
fail("Should not get here.");
}
@Override
public void onResponseReceived(Request request,
JsArray<SomeModelObject> deals) {
// TODO Validate the response.
assertEquals(1, deals.length());
SomeModelObject bo = deals.get(0);
assertEquals("A", bo.getAccountProductType());
finishTest();
}
});
public final native String getAccountProductType() /*-{
return this.accountProductType;
}-*/;
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment