Best practice for parameterizing a GWT application?

I have a Google Web Toolkit (GWT) application, and when I refer to it, I want to pass some arguments / parameters that it can use to dynamically retrieve data. For example. if it was a stock chart application, I would like my link to contain a symbol, and then the GWT application read it and made a request to some stock service. For example. http: // myapp / gwt / StockChart? symbol = GOOG will be a link to my StockChart GWT application and it will access my web service on the GOOG stock exchange.

So far I have used server-side code to add Javascript variables to the page, and then I read these variables using JSNI (native JavaScript interface).

For example:

In the HTML host:

<script type="text/javascript"> var stockSymbol = '<%= request.getParameter("symbol") %>'; </script> 

In the GWT code:

 public static native String getSymbol() /*-{ return $wnd.stockSymbol; }-*/; 

(Despite the fact that this code is based on real code that works, I modified it for this question so that I can stub somewhere)

However, this does not always work well in host mode (especially with arrays), and since JSNI was not in version 1.4 and the previous one, I assume there is a different / better way.

+6
gwt
source share
2 answers

If you want to read query string parameters from a query, you can use the com.google.gwt.user.client.Window class:

 // returns whole query string public static String getQueryString() { return Window.Location.getQueryString(); } // returns specific parameter public static String getQueryString(String name) { return Window.Location.getParameter(name); } 
+10
source share

It is also nice to “parameterize” a GWT application using hash values.

So instead

  http://myapp/gwt/StockChart?symbol=GOOG 

using

  http://myapp/gwt/StockChart#symbol=GOOG 

There are several good tools for such “parameters” through the GWT History Engine .

+1
source share

All Articles