tags:

views:

228

answers:

2

Hi

I need some configuration files, that can be changed without recompiling the project in my GWT application. However, the GWT i18n doesn't allow to be used serverside.

So what's the solution for getting configuration constants to be used serverside?

Thanks.

A: 

If you only need them on the server side then go with the standard java.util.Properties class. If you want to share constants between both then create an additional RPC service call to get the list of properties to your client.

Drejc
But java.util.Properties require a crazy amount of code for doing extremly simple things. I somewhat assumed GWT had a "smarter" solution for it, since it have a smart solution for clientside constants.
Claus Jørgensen
Also it seems it's completely GUESSWORK where the relative paths of Java starts when deployed in a WAR archive, gaaaaaaah -.-
Claus Jørgensen
I agree but GWT code is client side and it's optimized for that. You might find some other library which suits your needs. I have written the code for this ages ago and still use it.
Drejc
A: 

Getting the GWT i18n interfaces working on the server side is easy with a java.lang.reflect.Proxy.

  1. Our team put the GWT i18n properties files in the same location as the com.google.gwt.i18n.client.Messages classes they generate. They are then deployed in the same directory as the class files, somewhere under /classes, and are therefore on the webapp's classpath.

  2. Read in the ResourceBundle from the deployed properties file. With the previous step, finding the properties file is easy: it's the name of the GWT i18n interface.

  3. Proxy the GWT i18n interface on the server side and use the proxy's InvocationHandler to look up the right property in the ResourceBundle. Finding the right property is also easy: it's the name of the invoking Method.

You now have GWT i18n interfaces created on the server. You can edit the properties file and redeploy without recompiling. However the changed constants won't be picked up on the client side.

Bluu