How to best get data into a GWT app?

331 views
Skip to first unread message

Carsten

unread,
Jun 21, 2012, 6:11:45 PM6/21/12
to google-we...@googlegroups.com
Hi,

I dynamically create a website that holds my GWT app. The GWT app needs some JSON data to be initialized. Depending on the link users clicked the website that holds the GWT app should start it with a different JSON data string.

Since that data is in JSON format I would like to put the JSON data somehow unescaped in the website...this should be possible in a <script> TAG, right? How would I get access to that string inside the script tag in GWT?

Or is there a better way to embed the JSON string in the website and get it from within the GWT app?

Thanks,
Carsten

Joseph Lust

unread,
Jun 21, 2012, 10:31:52 PM6/21/12
to google-we...@googlegroups.com
One easy way would be to use the Dictionary object in GWT if you just have and associative array of key/value pairs. See the example code in the JavaDoc.

Sincerely,
Joseph

Carsten

unread,
Jun 22, 2012, 7:34:32 AM6/22/12
to google-we...@googlegroups.com
Thanks. Reading the Dictionary JavaDoc I thought this is the solution.

The problem is my JSON data string has an array with objects inside:

var CurrentTheme = {
  highlightColor: "#FFFFFF",
  shadowColor: "#808080",
  data: [{}, {}, {}]
 };

calling dictionary.get("highlightColor") works great but when I want to get the string that makes up my data array it returns: [object Object],[object Object],[object Object], ... etc ... ]

I guess I could work around this by escaping the data-array and thus turn it into a string. Or is there a better solution?

I also need to add a module <inherits name="com.google.gwt.i18n.I18N"/> I otherwise do not use if I want to use Dictionary.

I am wondering if there is perhaps some other way then Dictionary to easily get a simple JSON-string into GWT without importing another module, writing JSNI or escaping the JSON string?


Thanks,
Carsten

Dimitrijević Ivan

unread,
Jun 22, 2012, 10:25:19 AM6/22/12
to google-we...@googlegroups.com
You should use JSNI interface for that.

Carsten

unread,
Jun 22, 2012, 11:21:00 AM6/22/12
to google-we...@googlegroups.com
I've read that tutorial. It rather deals with getting data cross-site. My question is how do I get my hands on a Javascript-Object defined on the website from inside GWT? Once I have that object I can do the rest myself.

Joseph Lust

unread,
Jun 22, 2012, 11:36:18 AM6/22/12
to google-we...@googlegroups.com
Here is a tutorial on how to pull in JSON data using JSO Overlays.



Sincerely,
Joseph
Reply all
Reply to author
Forward
0 new messages