Reading from a property file in GWT

2,934 views
Skip to first unread message

Praveen Prabakaran

unread,
Oct 26, 2009, 12:04:38 PM10/26/09
to Google Web Toolkit, d_bh...@yahoo.com
Hi,

There's a URL in my GWT application which is hard-coded in a java
file. I need to change this by creating a property file which contains
the URL in the form of a key-value pair. But I'm not able to do so. Is
this a limitation in GWT? Can I not use GWT to read from a property
file and print it? .Also please let me know how to include a external
package (for eg. "com.google.gwt.core.ext.typeinfo") in GWT.

Warm Regards,
Praveen.

Sripathi Krishnan

unread,
Oct 26, 2009, 12:25:40 PM10/26/09
to google-we...@googlegroups.com, d_bh...@yahoo.com
See class com.google.gwt.i18n.client.Dictionary


--Sri


2009/10/26 Praveen Prabakaran <p.pra...@gmail.com>

Thomas Broyer

unread,
Oct 26, 2009, 1:20:11 PM10/26/09
to Google Web Toolkit


On 26 oct, 17:25, Sripathi Krishnan <sripathi.krish...@gmail.com>
wrote:
> See class com.google.gwt.i18n.client.Dictionary

I'd have rather say com.google.gwt.i18n.client.Constants ;-)

Sripathi Krishnan

unread,
Oct 26, 2009, 1:31:44 PM10/26/09
to google-we...@googlegroups.com
Oh yes - Constants work better than Dictionary in this case.

--Sri


2009/10/26 Thomas Broyer <t.br...@gmail.com>

rjcarr

unread,
Oct 27, 2009, 12:48:41 AM10/27/09
to Google Web Toolkit
You've already been answered, but I'll elaborate a bit.

I'm going to assume you mean reading a property file in the client.
If you mean reading a property file in the server then you should look
at java.util.Properties.

If you don't want to set up a service to obtain the contents of this
properties file then you're going to need to have something on the
server parse it (see java.util.Properties above), and then write the
contents dynamically (say, with JSP) into the client page so that your
GWT javascript can access it.

As others have pointed out, you can then use Dictionary to pick up the
values you're after (although I prefer to use JSNI and avoid using a
Dictionary). I haven't used Constants before, but it looks
interesting ... that might be an easier route.

Good luck!

Sanjeev Kulkarni

unread,
Oct 27, 2009, 12:55:16 AM10/27/09
to Google Web Toolkit
Hi,
It is possible. create a java file which is like below
public interface LoginConstants extends
com.google.gwt.i18n.client.Messages{
@DefaultMessage("Logging in..")
@Key("loggingIn.msg")
String loggingIn_msg();
}
And in the .properties file u just have to access this like below

loggingIn.msg = Logging in..

This works fine...

Ashish Khivesara

unread,
Jan 24, 2010, 4:01:36 PM1/24/10
to google-we...@googlegroups.com
Hi I am trying to do a simple constant lookup. com.google.gwt.i18n.client.Constants is what I need to use.

I created the interface

public interface PhotoConstants extends Constants{

String appName();
}

I am calling is in GWT Entry Point code as follows

PhotoConstants constants = (PhotoConstants)GWT.create(PhotoConstants.class);
Window.alert(constants.upnpAppName());

I created a PhotoConstants.properties file in war/ directory.


However I get the following Exception. 

This maybe because I dont have the properties file in the correct location?? The documentation does not say anything about it though...


12:57:20.298 [ERROR] [phototrial] No resource found for key 'upnpAppName'
com.google.gwt.i18n.rebind.AbstractResource$MissingResourceException: No resource found for key 'upnpAppName'
    at com.google.gwt.i18n.rebind.AbstractResource$ResourceList.getRequiredStringExt(AbstractResource.java:246)
    at com.google.gwt.i18n.rebind.SimpleValueMethodCreator.createMethodFor(SimpleValueMethodCreator.java:95)
    at com.google.gwt.i18n.rebind.AbstractLocalizableImplCreator.delegateToCreator(AbstractLocalizableImplCreator.java:313)
    at com.google.gwt.i18n.rebind.ConstantsImplCreator.emitMethodBody(ConstantsImplCreator.java:163)
    at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.genMethod(AbstractGeneratorClassCreator.java:265)
    at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.emitMethods(AbstractGeneratorClassCreator.java:233)
    at com.google.gwt.user.rebind.AbstractGeneratorClassCreator.emitClass(AbstractGeneratorClassCreator.java:116)
    at com.google.gwt.i18n.rebind.AbstractLocalizableImplCreator.generateConstantOrMessageClass(AbstractLocalizableImplCreator.java:133)
    at com.google.gwt.i18n.rebind.LocalizableGenerator.generate(LocalizableGenerator.java:121)
    at com.google.gwt.i18n.rebind.LocalizableGenerator.generate(LocalizableGenerator.java:98)
    at com.google.gwt.dev.javac.StandardGeneratorContext.runGenerator(StandardGeneratorContext.java:418)
    at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:38)
    at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
    at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
    at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
    at com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind(ShellModuleSpaceHost.java:119)
    at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:531)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:414)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:39)
    at com.google.gwt.core.client.GWT.create(GWT.java:98)
    at com.ashish.phototrial.client.PhotoTrial.onModuleLoad(PhotoTrial.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:369)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:185)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:380)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    at java.lang.Thread.run(Unknown Source)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---


Alexander

unread,
Jan 25, 2010, 3:34:34 AM1/25/10
to google-we...@googlegroups.com
Try to point exactly property file with @Key

2010/1/25 Ashish Khivesara <ashish.k...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Regards,
Alexander

Ashish Khivesara

unread,
Jan 25, 2010, 2:25:54 PM1/25/10
to google-we...@googlegroups.com
It was because my *.properties file was not in the right location (the same package as the MyConstants.java). 

Thanks
Ashish
Reply all
Reply to author
Forward
0 new messages