views:

35

answers:

1

I am using a tree control in my GWT application. The tree has different items based on the user logged in. One way to populate the tree would be to query the server from my GWT code to get a list of tree items. But since the items will always be shown would it not be better to include information regarding them in the page itself? I am looking for views to achieve this. Would it be possible to get a template engine like django to insert these values into GWT string variables at serving time? Then I can use these string variables to populate the tree. Or is there a better way to achieve this?

+2  A: 

I answered a very similar question in the GWT group last year, so you might want to take a look there.


The idea, as you said, is to embed this data inside the host page, instead of firing an additional GWT RPC request during the app's initialization. You can:

  1. Embed the data inside a JavaScript variable in your host page, and access it using the Dictionary class

    This is a simple solution, especially if your data is serializable as a dictionary of strings. You could use the templating engine of your choice to insert this data in your host page (Django's, Mustache, FreeMarker, JSP...).

  2. Embed a GWT-RPC payload inside your host page, as explained here and there

    This is better if you need to serialize a whole object graph (which might be what you want for your Tree widget, depending on its complexity). It's like a standard GWT-RPC request, but instead of sending an HTTP request at startup, the GWT-RPC "response" would have been be embedded inside your host page when you serve it.

eneveu
This is the correct answer. Another tutorial here: http://code.google.com/webtoolkit/articles/dynamic_host_page.html
Jason Hall
Wow, nice article. Didn't think about using JSNI to access the embedded data, but it also makes sense.
eneveu