简体   繁体   中英

wicket: fragment inside an AjaxLazyLoadPanel

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:

fragment4 = new Fragment4(id, "fragment4", CurrentPageOrPanelName.this);

The other possibility (not totally sure that this works) is to change your markup so that the fragment is inside the ALLP:

<span wicket:id="fragment4Span">
  <wicket:fragment wicket:id="fragment4">
  </wicket:fragment>
</span>

Your markup contains nothing to add the fragment to... ie there is no component with an id that can possibly match your id variable. You've got fragment4Span, which will be your LazyLoadPanel, you've got a Fragment with the fragment-id "fragment4" but no matching "receiver"...

See: The Wicket Examples about Fragments

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM