You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Christian Grobmeier <gr...@gmail.com> on 2011/01/29 17:17:46 UTC

User configuration files

Hello

I tried to figure out how one can load own configuration files into
wicket, for example with configuration on smtp host or something like
that.

It seems there is no standard way- is this correct? My solution is
below, but it feels rather overcomplicated to me.
I have overridden the init method and used the PropertiesFactory to
load my own properties file into a member variable of my application
class. I want my properties be available as long as the application
lives (application scope) and accessible from various components.

If you know any ways to make this easier, please let me know.

Thanks
Christian



In my WebApplication class:

	@Override
	public void init() {
...
 PropertiesFactory properties = new PropertiesFactory(this);
	    String configFile = "WEB-INF/config-deployment.";
	    if(RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType()))
{
	        configFile = "WEB-INF/config-development.";
	    }
	    Properties p = properties.load(TimeAndBillApplication.class, configFile);
	    if(p != null) {
	        applicationProperties = new
Properties("applicationProperties", p.getAll());
	    }

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: User configuration files

Posted by Christian Grobmeier <gr...@gmail.com>.
No.

I wanted to go with plain wicket. However, is it recommended by the
wicket team to use Spring? It is possible for me, but want to keep my
project as small as possible.

On Sat, Jan 29, 2011 at 5:23 PM, James Carman
<ja...@carmanconsulting.com> wrote:
> Are you using Spring?
>
> On Sat, Jan 29, 2011 at 11:17 AM, Christian Grobmeier
> <gr...@gmail.com> wrote:
>> Hello
>>
>> I tried to figure out how one can load own configuration files into
>> wicket, for example with configuration on smtp host or something like
>> that.
>>
>> It seems there is no standard way- is this correct? My solution is
>> below, but it feels rather overcomplicated to me.
>> I have overridden the init method and used the PropertiesFactory to
>> load my own properties file into a member variable of my application
>> class. I want my properties be available as long as the application
>> lives (application scope) and accessible from various components.
>>
>> If you know any ways to make this easier, please let me know.
>>
>> Thanks
>> Christian
>>
>>
>>
>> In my WebApplication class:
>>
>>        @Override
>>        public void init() {
>> ...
>>  PropertiesFactory properties = new PropertiesFactory(this);
>>            String configFile = "WEB-INF/config-deployment.";
>>            if(RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType()))
>> {
>>                configFile = "WEB-INF/config-development.";
>>            }
>>            Properties p = properties.load(TimeAndBillApplication.class, configFile);
>>            if(p != null) {
>>                applicationProperties = new
>> Properties("applicationProperties", p.getAll());
>>            }
>>
>> ---------------------------------------------------------------------
>> 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
>
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: User configuration files

Posted by James Carman <ja...@carmanconsulting.com>.
Are you using Spring?

On Sat, Jan 29, 2011 at 11:17 AM, Christian Grobmeier
<gr...@gmail.com> wrote:
> Hello
>
> I tried to figure out how one can load own configuration files into
> wicket, for example with configuration on smtp host or something like
> that.
>
> It seems there is no standard way- is this correct? My solution is
> below, but it feels rather overcomplicated to me.
> I have overridden the init method and used the PropertiesFactory to
> load my own properties file into a member variable of my application
> class. I want my properties be available as long as the application
> lives (application scope) and accessible from various components.
>
> If you know any ways to make this easier, please let me know.
>
> Thanks
> Christian
>
>
>
> In my WebApplication class:
>
>        @Override
>        public void init() {
> ...
>  PropertiesFactory properties = new PropertiesFactory(this);
>            String configFile = "WEB-INF/config-deployment.";
>            if(RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType()))
> {
>                configFile = "WEB-INF/config-development.";
>            }
>            Properties p = properties.load(TimeAndBillApplication.class, configFile);
>            if(p != null) {
>                applicationProperties = new
> Properties("applicationProperties", p.getAll());
>            }
>
> ---------------------------------------------------------------------
> 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: User configuration files

Posted by Christian Grobmeier <gr...@gmail.com>.
Igor,

thanks for your excellent tipps.

> the application settings are meant there for you to configure wicket,
> not your own application.

If ApplicationSettings is not to store settings for your application,
then I feel this name confusing. In the past years the name "webapp"
referred to my own webapplication, not the underlying framework.


> simply expose the properties in the application and then your
> components can get them like this:
>
> MyApplication.get().getProperty("foo");
>
> not so bad.

Yes, but I need to expose my applications class to the components,
which is not very generic and lets me create non-reusable stuff.
However, it is possible for prototyping or trivial apps.

> write a IComponentInstantiationListener and inject the properties, so
> you can have
>
> @Properties Properties props; fields in your component that are
> magically populated.

This is great thanks. I will use this now.

> there is no one way to do this, and its certainly not the job of the
> UI layer to handle it for you. thus we do not do it.

I understand there are hundreds of ways to go. But there should be at
least one "standard" way. Configuration of a web app is so basic. Even
UI frameworks need to be configured, at least when they are small
(prototyping). There are thousand ways for doing i18n, but wicket has
provided one way which can be extended.

> as a last note, you can leverage wicket's i18n to load properties
> stored in your MyApplication.properties.
> getString("myproperty") is all you need.

It feels a bit weird to use i18n for my configuration :-) But good to know :-)

Cheers + thanks for the conversation, I have learned much of it.
Christian

>
> -igor
>
>
> On Sat, Jan 29, 2011 at 11:02 AM, Christian Grobmeier
> <gr...@gmail.com> wrote:
>> On Sat, Jan 29, 2011 at 6:27 PM, Igor Vaynberg <ig...@gmail.com> wrote:
>>> that actually looks pretty simple to me...
>>
>> On first glance yes. But bringing the application parameters into
>> another component or api will become complicated.
>>
>> WIth this code I can only extend my Application with a new method
>> (getProperties). I have to introduce a new interface to make my
>> components generic, otherwise I need casting.
>>
>> I looked at the ApplicationSettings and I am wondering why this class
>> does not provide the functionality to set user defined parameters in
>> key/value manner. Are there any reasons against this? I can imagine a
>> loadUserProperties which does what I wrote below and stores the
>> key/values in ApplicationSettings.getValue( String 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
>
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: User configuration files

Posted by Igor Vaynberg <ig...@gmail.com>.
your class loads one file from one directory if app is in dev mode,
another if app in deploy mode. not everyone wants this. further we
would have the names of properties configurable. another pain. maybe
someone wants to use an xml file to load properties because key value
pairs are not enough, should we support that as well? the rabbit hole
goes down pretty far.

the application settings are meant there for you to configure wicket,
not your own application.

simply expose the properties in the application and then your
components can get them like this:

MyApplication.get().getProperty("foo");

not so bad.

write a IComponentInstantiationListener and inject the properties, so
you can have

@Properties Properties props; fields in your component that are
magically populated.

there is no one way to do this, and its certainly not the job of the
UI layer to handle it for you. thus we do not do it.

as a last note, you can leverage wicket's i18n to load properties
stored in your MyApplication.properties.

getString("myproperty") is all you need.

-igor


On Sat, Jan 29, 2011 at 11:02 AM, Christian Grobmeier
<gr...@gmail.com> wrote:
> On Sat, Jan 29, 2011 at 6:27 PM, Igor Vaynberg <ig...@gmail.com> wrote:
>> that actually looks pretty simple to me...
>
> On first glance yes. But bringing the application parameters into
> another component or api will become complicated.
>
> WIth this code I can only extend my Application with a new method
> (getProperties). I have to introduce a new interface to make my
> components generic, otherwise I need casting.
>
> I looked at the ApplicationSettings and I am wondering why this class
> does not provide the functionality to set user defined parameters in
> key/value manner. Are there any reasons against this? I can imagine a
> loadUserProperties which does what I wrote below and stores the
> key/values in ApplicationSettings.getValue( String 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: User configuration files

Posted by Christian Grobmeier <gr...@gmail.com>.
On Sat, Jan 29, 2011 at 6:27 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> that actually looks pretty simple to me...

On first glance yes. But bringing the application parameters into
another component or api will become complicated.

WIth this code I can only extend my Application with a new method
(getProperties). I have to introduce a new interface to make my
components generic, otherwise I need casting.

I looked at the ApplicationSettings and I am wondering why this class
does not provide the functionality to set user defined parameters in
key/value manner. Are there any reasons against this? I can imagine a
loadUserProperties which does what I wrote below and stores the
key/values in ApplicationSettings.getValue( String key)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: User configuration files

Posted by Igor Vaynberg <ig...@gmail.com>.
that actually looks pretty simple to me...

-igor

On Sat, Jan 29, 2011 at 8:17 AM, Christian Grobmeier
<gr...@gmail.com> wrote:
> Hello
>
> I tried to figure out how one can load own configuration files into
> wicket, for example with configuration on smtp host or something like
> that.
>
> It seems there is no standard way- is this correct? My solution is
> below, but it feels rather overcomplicated to me.
> I have overridden the init method and used the PropertiesFactory to
> load my own properties file into a member variable of my application
> class. I want my properties be available as long as the application
> lives (application scope) and accessible from various components.
>
> If you know any ways to make this easier, please let me know.
>
> Thanks
> Christian
>
>
>
> In my WebApplication class:
>
>        @Override
>        public void init() {
> ...
>  PropertiesFactory properties = new PropertiesFactory(this);
>            String configFile = "WEB-INF/config-deployment.";
>            if(RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType()))
> {
>                configFile = "WEB-INF/config-development.";
>            }
>            Properties p = properties.load(TimeAndBillApplication.class, configFile);
>            if(p != null) {
>                applicationProperties = new
> Properties("applicationProperties", p.getAll());
>            }
>
> ---------------------------------------------------------------------
> 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