Question

In Wicket, is it possible to have the value of one property reference another property? For example, if I had a property like <entry key="site.name">My Site</entry>, is there any way for another property to use the value of site.name in its value?

I tried using something like <entry key="page.title">About ${site.name}</entry> but Wicket throws an exception because it's trying to resolve site.name as a property of the model... which makes sense. But is there another syntax that would allow one property to refer to the value of another?

I'm running Wicket 6.6 by the way.

Was it helpful?

Solution

To answer my own question, a quick peak at the code shows that Wicket loads properties using java.util.Properties, which simply parses a stream for key-value pairs. It does not do any property expansion/substitution the way that developers might expect based on their experience with tools like ANT.

There are alternatives to Properties, like Apache Commons Configuration, that perform expansion but Properties does not. Therefore, neither does Wicket - it simply loads the properties as they are written. The only substitution Wicket does is for model properties when a page is rendered, not for properties in the "properties file" sense of the word.

OTHER TIPS

Have a look at StringResourceModel in Wicket.

Example in the doc: label.greetings=Welcome, ${name}! and new Label("greetings", new StringResourceModel("label.greetings", this, new Model(user)));

You can write your own ResourceModel that replaces the keys: http://pastebin.com/38WB2XDF

The ReplacingResourceModel will be available / is available in:

<dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>wicketstuff-minis</artifactId>
    <version>7.0.0-M6</version>
</dependency>

and

<dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>wicketstuff-minis</artifactId>
    <version>6.20.0</version>
</dependency>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top