开发者

How can I get data from a Freemarker template into GWT code?

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?


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜