3

I need to store a few configuration parameters on the client side of my GWT app--I'm only using the client side of the framework. I just want to store things like an API access URL base.

Ideally, it would be nice if this were dynamically read, but I can live with having the values statically baked in on every compilation.

When scouring the web for answers, I kept running into all the deferred binding and locale management stuff. I don't care about any of that. I just want to set some property like api.url and read it from the Java code. Failing that, I'd like to set it in an external JavaScript file and read it in from the main generated JS code somehow. However, keeping it simple is an important goal; I don't want to go down the path of some Rube Goldberg-esque JSNI monstrosity.

Is there any means of accomplishing that with some sort of properties files, or a simple JSNI import mechanism? Or am I pretty much stuck with using a Constants-based configuration class (which still requires a recompile to bake in)?

Alex Balashov
  • 3,218
  • 4
  • 27
  • 36
  • I don't know if what you need makes sense. With gwt you always need to recompile. So what is the problem with constants-based configuration class? – DiogoSantana Mar 27 '13 at 18:22
  • I suppose that is an element of my question. :-) If it has to be compile-time, so be it. But in that case, is there anything I can put in ModuleName.gwt.xml instead? I would much prefer that. – Alex Balashov Mar 27 '13 at 18:24
  • Yes you can. I used on one project. Let check on that, I will return. – DiogoSantana Mar 27 '13 at 18:30
  • You might want to consider a better example too - database server connection info is nothing the client (which runs in a web browser!) should ever know about. This is a server question, not a GWT one. – Colin Alworth Mar 27 '13 at 18:32
  • ...that said, a small bit of JS on your host page could feed to the Dictionary object, which internally does that JSNI 'monstrosity' work. – Colin Alworth Mar 27 '13 at 18:34
  • Yeah, it was a poor example. I hadn't thought through it. I'll edit the question. – Alex Balashov Mar 27 '13 at 18:34
  • Did you consider serving the configuration information from your node.js as json data and using that in GWT - https://developers.google.com/web-toolkit/doc/latest/tutorial/JSON – appbootup Mar 28 '13 at 03:23
  • I've certainly considered it, but that would require statically configuring the GWT client app to the URL from which to retrieve said data from Node.js. That will vary greatly across deployments. – Alex Balashov Mar 28 '13 at 14:07
  • possible duplicate of [Where to strore config parameteres in GWT?](http://stackoverflow.com/questions/8954823/where-to-strore-config-parameteres-in-gwt) – Bob Mar 22 '15 at 17:43

3 Answers3

3

This is what you're looking for: http://www.gwtproject.org/articles/dynamic_host_page.html

Bdoserror
  • 1,184
  • 9
  • 22
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
0

In order to escape from the compilations each time when configuration changed i would like to suggest the RPC call of configuration parameters in onmodule load.

In onsuccess you can assign those parameters to your Gwt static variables,those available throughout the Gwt code.

This may reduce the pain,you can change the parameters on serverside and deploy again,No Need To Compile each time for a single line change.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • The question is about "parameters on the client side" – DiogoSantana Mar 27 '13 at 19:05
  • Instead of reading values from another js file or from gwt.xml file which needs recompile, i feel this is coolway.now @alex have many choices from answers,let him pick which suites his requirment. – Suresh Atta Mar 27 '13 at 19:26
-2

You can define a property on the module xml. Like this:

<define-property values="desenv, production" name="environment"/>
<set-property name="environment" value="production"/>
DiogoSantana
  • 2,404
  • 2
  • 19
  • 24