Hi Thomas,

WicketMessageResolver has a lot of magic and I find it hard to decide which of these could be extracted into a stand-alone component (e.g. resolving properties from the parents model.

My question: Why don't you use a Panel instead, using different markup based on some condition?

Have fun

On 27.07.19 16:16, Thomas Heigl wrote:
Hi all,

I just gave this a try by copying the whole `MessageContainer` class to my
project and using it like this:

final MessageContainer c = new MessageContainer("msg", "test.msg", false);
c.add(new ExternalLink("link", Model.of("http://test.com";), new

This fails with a NPE because the MessageContainer assumes, that it has to
use its parent component for resolving any nested components, because the
`<wicket:message/>` tag is not a container by itself:

Component component = getParent().get(id);
if (component == null) {
component = ComponentResolvers.resolve(getParent(), markupStream,
currentTag, null);
         // Must not be a Page and it must be connected to a parent.
if (component.getParent() == null) {
component = null;

When used with a `<wicket:container />` or a `<div wicket:id="myId"/>` the
tag component itself has to be used to resolve nested components. It is
possible to fix this by replacing all calls to `getParent()` with a custom
method that checks if the tag is a wicket message or some other element,
but it does not feel right.

I could go ahead with my local copy of MessageContainer and adjust it for
my project but it contains a lot of logic that has to be duplicated like
message interpolation and markup stream parsing.

I'd be willing to provide a PR if someone in the development team has any
suggestions on how to approach this.



On Thu, Jul 25, 2019 at 9:17 AM Thomas Heigl <tho...@umschalt.com> wrote:

Hi Martin,

Sure. Currently I'm using <wicket:message> like described in the JavaDoc
of WicketMessageResolver:


   <wicket:message key="myKey">
         <span wicket:id="amount">[amount]</span>.
         <a wicket:id="link">
             <wicket:message key="linkText"/>


add(new Label("amount", new Model<String>("$5.00")));
add(new BookmarkablePageLink<Void>("link", DetailsPage.class));


myKey=Your balance is ${amount}. Click ${link} to view the details.

This works, but the key "myKey" cannot be changed during runtime. I'd like
to use the private MessageContainer the same way I can use an


   <wicket:container wicket:id="msg">
         <span wicket:id="amount">[amount]</span>.
         <a wicket:id="link">
             <wicket:message key="linkText"/>


final String key = "myKey";
final MessageContainer msg = new MessageContainer("msg", key, true);

msg.add(new Label("amount", new Model<String>("$5.00")));
msg.add(new BookmarkablePageLink<Void>("link", DetailsPage.class));

I hope that explains my requirement a bit better.



On Thu, Jul 25, 2019 at 6:48 AM Martin Terra <
martin.te...@koodaripalvelut.com> wrote:


Can you show an example of solution now vs. solution after change, what
the benefits of such visibility change to your case? Maybe there is
way to accomplish your goal?


ke 24. heinäk. 2019 klo 22.25 Thomas Heigl (tho...@umschalt.com)

Hi all,

I'd like to create Wicket messages with child components
Currently, this is only possible by using the <wicket:message> tag and
nesting components inside of it.

For most use cases this is sufficient, but I sometimes come across cases
where I'd like to programatically define the message key instead of
hard-coding it in the template.

The class that does all the interpolation is currently

Would it be possible to make this a public (top-level) class in Wicket
If I understand correctly, this would solve my requirement without any
other code changes.

Best regards,


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

Reply via email to