简体   繁体   中英

Is there a method of BreadCrumbBar I can overload to add an extra Component to be refreshed?

I have a wicket page with a data panel that makes use of the BreadCrumbBar (org.apache.wicket.extensions.breadcrumb). If I go down a level a new breadcrumb is automatically added and the data panel is refreshed. If I click on one of the previous breadcrumbs my data panel gets updated correctly. Now I want to make sure some extra Component on the page (the title) also gets updated. This works fine when I control the link myself, but for the breadcrumb links I don't have full control.

Is there a method of BreadCrumbBar I can overload to add the extra Component to be refreshed? I assume the links in the BreadCrumbBar are ajax links, but I cannot find an ajax target in the BreadCrumbBar (or any of the child components).

By default, BreadCrumbBar uses BreadCrumbLink s to render its links, which are usual Link s (and not AjaxLink s).

To get an ajax behavior, you could try to create your own link ( BreadCrumbAjaxLink ) implementation using AjaxLink as a base and implement in onClick(AjaxRequestTarget) the same logic that exists in BreadCrumbLink 's onClick() .

Then create an analogue of BreadCrumbComponent (let's call it AjaxBreadCrumbComponent ) using your BreadCrumbAjaxLink instead of BreadCrumbLink .

And then override BreadCrumbBar 's newBreadCrumbComponent() method:

protected Component newBreadCrumbComponent(final String id, final long index, final int total,
    final IBreadCrumbParticipant breadCrumbParticipant)
{
    boolean enableLink = getEnableLinkToCurrent() || (index < (total - 1));
    return new AjaxBreadCrumbComponent(id, getSeparatorMarkup(), index, this,
        breadCrumbParticipant, enableLink);
}

In BreadCrumbAjaxLink , you could update whatever additional component you want. (You would probably need to update the bar itself too).

Since extending several classes seemed a bit overkill for my use case, I tried something different that eventually worked.

By overloading the setActive method of the BreadCrumbBar I could set some text to the page title model. That text was then shown on the page.

I am still not sure how the BreadCrumbBar handles this. I think the entire page is refreshed and no ajax call is done.

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