2

I need to dynamically change the loaded keys through a parameter. Imagine there yould be 2 properties like

<entry key="property.to.load.somesuffix">value1</entry>
<entry key="property.to.load.anothersuffix">value2</entry>

loading these based on the values of the model of the pageclass could be accomblished, for example, with a stringresourcemodel like

new StringResourceModel( "property.to.load.${pageParam.suffix}", this, new Model(pageModel))));

and adding this resource model to a label and render the loaded value of the property in that label. but I need to render the properties value as usual html text as it is rendered by using the wicket:message tag for example like

<wicket:message key="property.to.load.${pageParam.suffix}" />

this, off course, does not work. Any Solutions for that? Maybe Override the internal functionality of the interpretation of the wicket:message tag ?!

Edit

Although the text rendering in the Label seems to be very well, as stated below, and you can set the escapemodelstring, it might be useful to have a possibility to this kind of parameterizing in wicket:message tag and not to add a label for every key.

This issue might be a big Problem from the perspective, that you wont want to have any java code specific stuff in your markup like model specific method names in the keyparameter. So there would be also a need for a generalization of this technique. any ideas to accomblish that?

Mar Cel
  • 420
  • 3
  • 12
  • Well I don't know a solution with wicket:message, but what is the problem of the Label alternative? – jordeu Mar 31 '12 at 15:09
  • the text is being rendered differently. kind of like an image, not like normal text. the usual stylesheets do not style the text anymore, the font isnt correct and no html tags within the properties value can be rendered. – Mar Cel Mar 31 '12 at 15:13
  • You mean that your property contains HTML tags inside? – jordeu Mar 31 '12 at 15:16
  • yes. the whole internationalization is solved with xml properties. these contain simple formatting tags like and
    .
    – Mar Cel Mar 31 '12 at 15:18
  • Implementing your own ResourceLoader is rather simple. The problem is, that the IStringResourceLoader does not have knowladge of the ${pageParam.suffix}. Only suggestion i can offer is to have some helper function where you pass in the information to build the resource key – bert Mar 31 '12 at 19:56

2 Answers2

2

May be you can still use your

new StringResourceModel( "property.to.load.${pageParam.suffix}", this, new Model(pageModel))));

with a Label that don't escape the HTML tags of your property

add(new Label("label", "<strong>my html property</strong>").setEscapeModelStrings(false));
jordeu
  • 6,711
  • 1
  • 19
  • 19
  • thats not a bad idea, ill try that. although the html excaping itself isnt really the whole point. – Mar Cel Mar 31 '12 at 15:23
  • well this actually worked pretty well. surprisingly the text of the label has been rendered very good, independent from the escaping. I made the experiance, that the rendered text in the label can be kind of ugly, depending on what you ar trying to view. maybe this was a problem of some older version. indeed the escapemodelstring worked as well, that was something I completely forgot. thank you very much – Mar Cel Mar 31 '12 at 15:33
  • Ok, perfect, I'm happy that this was a good solution for you. – jordeu Mar 31 '12 at 15:40
  • this does solve my problem of viewing the correct keys value, but I also like to have a solution for parameterizing the wicket:message tag. – Mar Cel Mar 31 '12 at 15:43
0

I found a good article which describes how to customize the behaviour of a wicket tag or implement your own one.

Mar Cel
  • 420
  • 3
  • 12