You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael Mehrle <mi...@ask.com> on 2008/06/02 00:49:56 UTC
How to access properties files outside of Wicket components?
I just refactored one of my pages and externalized an inner class into
an outer class that however still needs access to that page's property
stings. Can I just treat that page's properties file as a resource
bundle and retrieve the strings the old fashioned way? Or will there be
problems?
Thanks,
Michael
Re: How to access properties files outside of Wicket components?
Posted by Erik van Oosten <e....@grons.nl>.
Look carefully. Your code sample does:
Thread.currentThread().getContextClassLoader().getResourceAsStream("MyComponent.properties")
Which loads it from the default package.
I think you should do:
MyComponent.class.getResourceAsStream("MyComponent.properties")
Which loads it from the package MyComponent is in.
Regards,
Erik.
Michael Mehrle wrote:
> That's what I have been doing, mate ;-)
>
> I'm looking for a solution that allows me to load the properties file
> out of the same folder as my class or WEB-INF. Not working right now and
> I pretty much tried all approaches I could find online.
>
> Wicket does not offer a way to access resource bundles outside of Wicket
> components?
>
> Michael
>
> -----Original Message-----
> From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
> Sent: Sunday, June 01, 2008 10:32 PM
> To: users@wicket.apache.org
> Subject: Re: How to access properties files outside of Wicket
> components?
>
> You should the other getResource*() methods, those on Class:
> http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAs
> Stream(java.lang.String)
>
> Regards,
> Erik.
>
>
> Michael Mehrle wrote:
>
>> Right now I had to resort to the solution below, but I would very much
>> like to know the standard way of doing this, as this required me to
>> place my properties file into the src/main/resources folder:
>>
>> static {
>> try {
>>
>>
>>
> properties.load(Thread.currentThread().getContextClassLoader().getResour
>
>> ceAsStream(
>> "MyComponent.properties"));
>> } catch (Exception e) {
>> LOG.error("Unable to load file
>> MyComponent.properties' - error: {}", e.getMessage(), e);
>> }
>> }
>>
>> public static String getProperty(String key) {
>> return properties.getProperty(key);
>> }
>>
>>
--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: How to access properties files outside of Wicket components?
Posted by Michael Mehrle <mi...@ask.com>.
That's what I have been doing, mate ;-)
I'm looking for a solution that allows me to load the properties file
out of the same folder as my class or WEB-INF. Not working right now and
I pretty much tried all approaches I could find online.
Wicket does not offer a way to access resource bundles outside of Wicket
components?
Michael
-----Original Message-----
From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
Sent: Sunday, June 01, 2008 10:32 PM
To: users@wicket.apache.org
Subject: Re: How to access properties files outside of Wicket
components?
You should the other getResource*() methods, those on Class:
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAs
Stream(java.lang.String)
Regards,
Erik.
Michael Mehrle wrote:
> Right now I had to resort to the solution below, but I would very much
> like to know the standard way of doing this, as this required me to
> place my properties file into the src/main/resources folder:
>
> static {
> try {
>
>
properties.load(Thread.currentThread().getContextClassLoader().getResour
> ceAsStream(
> "MyComponent.properties"));
> } catch (Exception e) {
> LOG.error("Unable to load file
> MyComponent.properties' - error: {}", e.getMessage(), e);
> }
> }
>
> public static String getProperty(String key) {
> return properties.getProperty(key);
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to access properties files outside of Wicket components?
Posted by Erik van Oosten <e....@grons.nl>.
You should the other getResource*() methods, those on Class:
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
Regards,
Erik.
Michael Mehrle wrote:
> Right now I had to resort to the solution below, but I would very much
> like to know the standard way of doing this, as this required me to
> place my properties file into the src/main/resources folder:
>
> static {
> try {
>
> properties.load(Thread.currentThread().getContextClassLoader().getResour
> ceAsStream(
> "MyComponent.properties"));
> } catch (Exception e) {
> LOG.error("Unable to load file
> MyComponent.properties' - error: {}", e.getMessage(), e);
> }
> }
>
> public static String getProperty(String key) {
> return properties.getProperty(key);
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: How to access properties files outside of Wicket components?
Posted by Michael Mehrle <mi...@ask.com>.
Right now I had to resort to the solution below, but I would very much
like to know the standard way of doing this, as this required me to
place my properties file into the src/main/resources folder:
static {
try {
properties.load(Thread.currentThread().getContextClassLoader().getResour
ceAsStream(
"MyComponent.properties"));
} catch (Exception e) {
LOG.error("Unable to load file
MyComponent.properties' - error: {}", e.getMessage(), e);
}
}
public static String getProperty(String key) {
return properties.getProperty(key);
}
-----Original Message-----
From: Michael Mehrle [mailto:michael.mehrle@ask.com]
Sent: Sunday, June 01, 2008 3:50 PM
To: users@wicket.apache.org
Subject: How to access properties files outside of Wicket components?
I just refactored one of my pages and externalized an inner class into
an outer class that however still needs access to that page's property
stings. Can I just treat that page's properties file as a resource
bundle and retrieve the strings the old fashioned way? Or will there be
problems?
Thanks,
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org