On Mar 21, 8:00 pm, "A. Kong" <[email protected]> wrote: > Hi, all, > > I am still encountering some problem with JsonpRequestBuilder. I hope > anyone may point out what's why with my code. > > Basically I have a json server which emits the following data: > > ==== > > [{'Article': {'title': 'Main test2010-03-17 19:21:54.865390'}}, > {'Article': {'title': 'Main test2010-03-17 19:25:19.773520'}}] > > ==== > > On GWT front, I have > > ==== > > public void onModuleLoad() { > > JsonpRequestBuilder requestBuilder = new > JsonpRequestBuilder(); > requestBuilder.setCallbackParam("callback"); > requestBuilder.requestObject(SERVER_URL, new > MyTestRequestCallback()); > > } > > class MyTestRequestCallback implements > AsyncCallback<JsArray<Article>> { > > @Override > public void onFailure(Throwable caught) { > Window.alert("Failed to send the message: " + > caught.getMessage() + > " " + caught.getStackTrace()[0].toString()); > } > > @Override > public void onSuccess(JsArray<Article> result) { > Window.alert(result.get(0).getTitle()); > } > > ==== > > And here is my definition of Article class > > ==== > public class Article extends JavaScriptObject { > > protected Article() {}; > > public final native String getTitle() /*-{ return this.title; }-*/; > > } > > ==== > > The problem is: the result of "result.get(0).getTitle()" is always > null. > > Setting the break point in the onSuccess() does not help much. The > content of the valuable is a 'ref n' where n is a number (in the debug > perspective of eclipse) > > My questions are > 1) What is the likely cause of the failure of capturing 'title'? Any > obvious error in my code?
Your code does the JS equivalent to "the_array[0].title" while given the data snippet you gave it should be the_array[0].Article.title. > 2) I tried to debug in firebug, but failed to locate where the parsing > of json occurs. When I compiled the project, I used "output style" = > detailed. When I search for ".title" i could not find anything. > Shouldn't the native code be captured in the generated gwt code > intact? There's no "JSON parsing" with "JSON-P" as it's just JavaScript, not JSON at all. IMO, you should find ".title" but maybe it has been rewritten as the_obj["title"], with the String "interned" in a "global" variable. Search for ".alert" instead ;-) -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
