I’m trying to add fragment inside a repeating li component:
<ul>
<li wicket:id="listView">HERE GOES MY FRAGMENT</li>
</ul>
The code to populate the listview is the following:
@Override
protected void populateItem(final org.apache.wicket.markup.repeater.Item<Message> item) {
Message msg = item.getModelObject();
log.info("Adding message fragment to markup: " + item.getMarkupId());
item.add(new MessageFragement(item.getMarkupId(), "messageFragment", this, msg));
}
The generated expected code is:
<ul>
<li .... wicket:id="listView></li>
<li .... wicket:id="listView></li>
....
</ul>
But my fragment is not added and I receive the Runtime wicket exception:
The component(s) below failed to render. A common problem is that you
have added a component in code but forgot to reference it in the
markup (thus the component will never be rendered).
Why I cannot use the item markup id as componenent id for my fragment?
I now this can be easily solved by adding an additional tag on the li:
<ul><li wicket:id="listView"><div wicket:id="message"></div></li></ul>
And add the markup id “message” to the fragment. But I don’t want it. I just want to use the already there <li> to host my fragment, is it even possible?
Thanks guys
I think I found a solution, or better, a workaround.
I do leave the container tag for the Fragment in the <li>:
After that in the MessageFragment I just set in the Fragment constructor to not render the container tag using the setRenderBodyOnly(true) function:
And the result is as expected: