views:

459

answers:

1

I am building a tree structure which an object references itself in like so:

public class ProjectObjectOL extends JavaScriptObject {

    protected ProjectObjectOL() { }


    public final native boolean getStatus()  /*-{ return this.status;  }-*/;
    public final native String getError()  /*-{ return this.error_message;  }-*/;

    public final native JsArray<ProjectObjectOL> getChildren() /*-{ this.children; }-*/;


}

My problem is that I can't seem to get the children of the object. I've tested it out, and I'm quite sure the JSON structure being passed back consists of an object that contains an array of children of that type which can contain children, etc.

...but when trying to access even the simplest information about the children, the length of the array, it returns 0 every time. I've tried with no success to figure out what it's doing wrong, all the other data returns fine, but this one piece will NOT retrieve the children. Here is an example of how I might (directly) access the length for testing:

JSONObject oResults = (JSONObject) JSONParser.parse(response.getText());
              ProjectListOL testoutputOL = oResults.isObject().getJavaScriptObject().cast();
              ProjectObjectOL testObject = testoutputOL.getProjectList().get(1);
              Window.alert(testObject.getChildren().length()+"");

A ProjectListOL contains an array of ProjectObjectOLs. In the example above I simply grabbed the one I KNOW has children. I'm using ColdFusion for the backend that returns the JSON object. Once again, I have output this object multiple times, both in GWT and outside (directly dumping the JSON object from the file) verifying that the object is indeed set up how I expect it to be set up.

+1  A: 

I missed an obvious mistake:

public final native JsArray<ProjectObjectOL> getChildren() /*-{ this.children; }-*/;

OOPS:

public final native JsArray<ProjectObjectOL> getChildren() /*-{ **return** this.children; }-*/;
Organiccat
lol - the dangers of dynamically typed languages!
Chii