[Developers] Calling Freebase from GWT?
Alison Lee
alee at metaweb.com
Thu Mar 29 18:50:57 UTC 2007
There are several issues to address in doing this.
First, Google Web Toolkit (GWT) supports building AJAX application in
Java. It provides a nice wrapper around XMLHttpRequest. However,
cross-site issues prevent that approach to work for normal Freebase
application where the GWT application host and the Freebase query
server run at different sites. Section
4.5.2 of Developing Metaweb-Enabled Web Applications (http://
www.freebase.com/view/documentation/) describes several workarounds
to the cross-site issues. GWT's developer site provides information
and an example of how to dynamically fetch JSON feeds from other web
domains (http://code.google.com/support/bin/answer.py?
answer=55954&topic=10394). Note: the approach works but the some of
the description and the code snippets are buggy. In summary, an
approach is to:
a) use a dynamically created script tag with a mqlread URL and a
callback parameter in the GWT application,
b) use the GWT approach to define a JSON callback into Java from
external Javascript.
Second, aside from the errors in the above-mentioned GWT example,
there are issues to be aware of. For example, because a GWT is
loaded in a zero-size IFrame inside the main document, this prevents
"x instanceof Array" from working with the data returned by JSON.
For details, see the discussion in GWT Google Groups (http://
groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/
b750195091da28cb/1ba006b4577365a8?
lnk=gst&q=instanceof&rnum=10#1ba006b4577365a8). Therefore, processing
the JavaScriptObject provided by the JSON callback requires writing
some JSNI code and using a workaround to test for arrays.
Without further ado, here's an application example that displays the
MQL query result in a GWT tree widget.
http://www.webcollab.com/freebase/gwtmqlread/
Alison
P.S.: GWT is available from http://code.google.com/webtoolkit/
> -----Original Message-----
> From: developers-bounces at freebase.com
> [mailto:developers-bounces at freebase.com] On Behalf Of William Pietri
> Sent: Tuesday, March 20, 2007 3:16 PM
> To: developers at freebase.com
> Subject: [Developers] Calling Freebase from GWT?
>
> Has anybody managed to call the Freebase API from a GWT component?
> I'm a
> Javascript tyro, and I'm struggling to get it properly bound in
> with JSNI.
> My current hurdle, which I think I'll get past shortly, is getting
> the call
> to happen at all. But the one that scares me is getting callbacks
> to work
> properly on result arrival.
>
> Thanks,
>
> William
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
More information about the Developers
mailing list