私はまだJSONとGWTにかなり慣れていないので、JSONデータをページからGWTアプリに戻す方法を見つけようとしています。JSON をクラスに返します。
public class GetProductTree extends JavaScriptObject {
protected GetProductTree() { }
public final native String getCustomerName() /*-{ return this.customername; }-*/;
}
これは非常に基本的なものであり、現時点では完全ではないため、(今のところ) 何かを取り戻すことができるようにしています。
これを呼び出すコードは次のとおりです。
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) {
}
}
});
ただし、エラーが発生します。
タイプ XYZ.GetProductTree のソース コードはありません。必要なモジュールを継承するのを忘れましたか?
呼び出しページで XYZ.GetProductTree の正しいパッケージをインポートしています。私は何が欠けていますか?