I'm still pretty new to JSON and GWT and I'm trying to figure out how to pass JSON data back from a page into my GWT app. I pass the JSON back to a class:
public class GetProductTree extends JavaScriptObject {
protected GetProductTree() { }
public final native String getCustomerName() /*-{ return this.customername; }-*/;
}
It's pretty basic and not complete at this moment so I'm just trying (for now) to make sure I can get something back.
The code to call this is:
submitProject.addClickListener(new ClickListener() {
public void onClick(Widget w) {
RequestBuilder.Method method=RequestBuilder.GET;
final String url1 = "http://localhost:8500/getProducts.cfm";
//Window.alert(url1);
RequestBuilder rb = new RequestBuilder(method, url1);
try {
rb.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
JSONObject oResults = (JSONObject) JSONParser.parse(response.getText());
GetProductTree oResponse = oResults.isObject().getJavaScriptObject().cast();
Window.alert(oResponse.getCustomerName());
}
public void onError(Request arg0, Throwable arg1) {
Window.alert("error");
}
});
} catch (RequestException e) {
}
}
});
However I get an error:
No source code is available for type XYZ.GetProductTree; did you forget to inherit a required module?
I am importing the correct package for XYZ.GetProductTree on the call page. What am I missing?