views:

32

answers:

1

I have a webapp setup that uses Stripes and Freemarker; for part of it I'm also coding some GWT stuff, and I'm trying to figure out the best way of getting information from the actionBean into GWT code. Currently I do this in the template:

<script>
  var params = {
    nick : "${actionBean.nick}",
    logout: "${actionBean.logout}"
  }
</script>

And then I do a Dictionary.getDictionary("params") on entry into the GWT module. It works fine, but I feel like I could do better. Suggestions?

A: 

The "compile everything into a bunch of static .js" GWT-policy doesn't allow modification of the js itself. It allows -using a strong name technique- to cache all the GWT code in the browser.

So if any dynamic data must get inside the GWT widget it must come from outside. And your widget will have to go for it. So declaring this Dictionary seems the correct way to do it (I did this in my job).

An option would be generate a JavaScript friendly GWT widget with gwt-exporter (I mean, a Javascript class with readable names for class and methods). Then your javascript could inject the values itself making the GWT widget ignorant of its context. Something like:

var x = new MyExportedWidget();
x.addTo(somePanel);
x.setProperty(value);

But it seems overkill...

helios