开发者

Serverside configuration constants in GWT

开发者 https://www.devze.com 2022-12-19 17:14 出处:网络
I need some configuration files, that can be changed without recompiling the project in my GWT application. Ho开发者_C百科wever, the GWT i18n doesn\'t allow to be used serverside.

I need some configuration files, that can be changed without recompiling the project in my GWT application. Ho开发者_C百科wever, the GWT i18n doesn't allow to be used serverside.

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

Thanks.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号