javaapachewicketwicket-7

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).


Solution

  • By default, BreadCrumbBar uses BreadCrumbLinks to render its links, which are usual Links (and not AjaxLinks).

    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).