tags:

views:

69

answers:

1

In my GWT app, I have an anchor that links to an external URL. I would like to make that URL configurable by a server flag. So my question is, how can I make the server flag accessible to the GWT presenter / view? I can create a servlet that returns the value of that flag so that the GWT side can make an RPC call to get the value, but I'm wondering if there is a better way to handle this.

+1  A: 

Step One

Replace your index.html (or whatever HTML page you send to the client with a for your GWT code) with a servlet that renders the same HTML.

Step Two

In that servlet, print out something like

<script type="text/javascript">
  var info = {url:'http://url.com'}; // TODO put other stuff here
</script>

Step Three

In your GWT code, do this:

Dictionary info = Dictionary.getDictionary("info");

Now you have a GWT object from which you can get your URL, like so:

String url = info.get("url");

It's like magic!

This is generally really useful for passing static server-side information that you need on page load, and you know will never change, things like the logged-in user's username, etc., and the like.

If you want to be able to change the data, or react to the data changing otherwise, you need to make an RPC to get it from the server at page load.

Jason Hall
Works great. Thanks!
smallbec