Hi, Thomas,

Thanks very much for the quick reply!

I am away from the workstation where the work is, so I cannot give
your suggestion a go yet.

But I have a question about the remedy you suggested, namely to access
the 'title' field using '_array[0].Article.title'

In my case, I would have expected GWT to be able to understand the
JSON "[]" representation as an array. GWT should be able to dispatch
each individual element in the array to Article class, which will use
native methods to map out individual attributes. That's why I assume
"this" in "this.title" correspond to "Aritcle:{...}"

Now let's say I changed the native code to 'array[0].Article.title'.
Then what will happen if i use another server interface that returns a
single Article? The callback will now become AsyncCallback<Article>
and array is not present in the json data.

I hope I did not sound too confusing. Maybe there is a gap in how I
understand the JNI works

Cheers



On Mar 22, 9:43 am, Thomas Broyer <[email protected]> wrote:
> 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.

Reply via email to