I want to render some wicket fragments on a page with lazy loading. The Java sample is below:
staticPanel.add(new AjaxLazyLoadPanel("fragment4Span") {
@Override
public Component getLazyLoadComponent(String id) {
fragment4 = new Fragment4(id, "fragment4", this);
fragment4.add(propertyLoop4);
return fragment4;
}
});
And the html component:
<span wicket:id="fragment4Span"></span>
<wicket:fragment wicket:id="fragment4">
</wicket:fragment>
But i get the exception below:
org.apache.wicket.markup.MarkupException: Markup of component class `org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel` does not contain a fragment with wicket:id `fragment4`. Context: [MarkupContainer [Component id = content]]
at org.apache.wicket.markup.html.panel.Fragment.renderFragment(Fragment.java:262)
at org.apache.wicket.markup.html.panel.Fragment.onComponentTagBody(Fragment.java:212)
at org.apache.wicket.Component.renderComponent(Component.java:2680)
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1538)
What can be the reason of it? I could not find an answer by googling by the way.
You pass
this– which references the AjaxLazyLoadPanel instance – as the fragment container. But as the error message states it doesn’t contain the fragment. Whis is true, because your page/panel does.So you actually need to pass a reference to your page/panel to the Fragment constructor:
The other possibility (not totally sure that this works) is to change your markup so that the fragment is inside the ALLP: