7

Where I can store configuration parameters in client side? I haven't possibility to store parameters in Servlet init parameters(web.xml) (because I must use PHP). So how I can store init application parameters (for example PHP script location, some passwords etc.) on client side?

Cœur
  • 37,241
  • 25
  • 195
  • 267
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286

5 Answers5

4

To do this you have a following options:

  1. Store data in client side code. GWT compiles down to the javascript and the simplest way to do this is to create a Configuration class with hardcoded values.
  2. Store data in a browser. You can use cookies or HTML5 local storage
  3. Store data on a server side and retrieve them using remote RPC.

I would recommend you go with third option.

Mairbek Khadikov
  • 7,939
  • 3
  • 35
  • 51
  • thank you, but what about some file, where I can change URL's of php script location AFTER compiling? Issue with Configuration class not good. For retreiving information from server my app need to know server URL :) I dont want to hardcode server URL, i want to exclude it into some file, which can be read at RUNTIME/ – WelcomeTo Jan 22 '12 at 17:47
  • GWT code is java and it has to be compiled and there are no property files at client side. The alternative is to store information in some JS file which can be replaced at runtime. – Mairbek Khadikov Jan 22 '12 at 19:58
3

You will probably be very happy using the Dictionary and Cookie classes in GWT.

In your html hosting file, you maintain some javascript objects declared as var.

At module load, call Dictionary class to grab the javascript objects that you have defined to store your config data.

In this way, you could have a server side managed user- or context- sensitive configuration, because occasionally I use JSP to generate the hosting file. I could manage user configuration as server side cookies stored in a database.

So ... today is Thursday ... the user has a history of visiting Manchester Utd FC web site every Thur, etc, let me give the user a different config based on context/user-sensitive algorithm. And on Monday mornings, the user config would include ad data for 10 hour energy beverages.

In this way, your gwt client would not have to request context-sensitive config data from the server.

But then of course, this is no way to store authentication/security data like passwords. I don't think you should even consider storing authentication/security data in client-side code. Even after javascript obfuscation, storing such data this way is an open invitation to persistence of malicious intent. Such data, if client-side storage is desired, would be best served by client-side cookies, using the GWT class Cookies.

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
1

Storing passwords on client side? OK, if you want to. Just create a class that will hold them, could be a static field, or a singleton object with all the parameters. Could even be the one with entryPoint().

milan
  • 11,872
  • 3
  • 42
  • 49
1

Standard, simple and easy way to store non-constant parametres(such as passwords, or any user data) on client side is cookies. See Cookies

Constant parameters you can store in hardcode(static fields in some class) or in resoures .properties files(See GWT i18n constants interface).

PS: I will not recomment you to store password on client side "as is"(it is not safe), instead you can store password hash(md5, for example). Just calculate password hash on server side and store this hash in cookies.

0

You can use MultiValuedConfigProperties (see also this other helpful tutorial) to store configuration values. Using them, you can store your configuration in your module's .gwt.xml configuration file. The configuration values will be compiled into the JavaScript output.

Bob
  • 5,510
  • 9
  • 48
  • 80