Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <wicket:message> tag to produce partially formatted text

Tags:

wicket

I've read about wicket:message here, but can't seem to make it do everything I'd like.

Say I have a HTML page with <wicket:message key="text"/> and a properties file containing text=Blah blah: important point, foo bar. I'm wondering how to make part of the text bold (or apply arbitrary CSS to it), to achieve output like:

Blah blah: important point, foo bar

Note that none of this is actually dynamic, so I wouldn't want to do anything in Java, if that can be avoided.

I've tried nesting tags with something like the following, but no luck.

<wicket:message key="text">
    <span class="bold"><wicket:message key="text2"/></span>
</wicket:message>

text=Blah blah: ${text2}, foo bar
text2=important point

Is this even possible in Wicket without 1) injecting the formatted part from Java side or 2) just splitting the text into (in this case) three different properties?

like image 505
Jonik Avatar asked Dec 08 '10 12:12

Jonik


1 Answers

The easiest way is to put the tags inside your localization file:

text=Blah blah: <strong>text2</strong>, foo bar

You could also use a Label and a ResourceModel to replace it later:

text=Blah blah: [b]text2[/b], foo bar

And in your model getObject(), or in your Label:

string.replace("[b]", "<strong>");
string.replace("[/b]", "</strong>");

Or, even better, try to reuse a Markdown implementation in your Label.

like image 69
Daan Avatar answered Jan 02 '23 23:01

Daan