1

我对 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 导入正确的包。我错过了什么?

4

2 回答 2

2

此错误来自编译器,抱怨它在其类路径中找不到该类型。为了让 GWT 编译器找到你的类,它们必须在你的类路径中,并且它们也必须在 .gwt.xml 模块文件中被引用。您可以发布您的包名称和 .gwt.xml 文件的内容吗?我的猜测是,无论你把这个类放在哪里,GWT 编译器都看不到它。

于 2009-02-01T20:55:33.713 回答
0

我有时候就是这么迟钝。我忘记了必须为我的新包添加源路径。我将它添加到我刚刚创建的“数据”包中,并没有将路径添加到 XML。谢谢 :)

于 2009-02-01T21:30:56.137 回答