views:

846

answers:

2

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?

+2  A: 

This error is from the compiler, complaining that it can't find that type in it's classpath. For the GWT compiler to find your classes they have to be and in your classpath, and they have to be referenced in a .gwt.xml module file as well. Can you post your package names and the contents of your .gwt.xml files? My guess is that wherever you have put this class it's not visible to the GWT compiler.

rustyshelf
A: 

I am so obtuse sometimes. I forgot about having to add the source path for my new package. I added this to a "data" package which I just created and didn't add the path to the XML. Thanks :)

Organiccat