I am trying to implement Breadcrumb Navigation on a WebPage
that exchanges a content Panel
via ajax.
It ends up looking like this:
Home >> Page >> Panel
Here is my page code:
public MyPage() {
super();
contentContainer = new WebMarkupContainer("contentContainer");
contentContainer.setOutputMarkupId(true);
add(contentContainer);
contentContainer.add(content = createContentPanel());
breadCrumbContainer = new WebMarkupContainer("breadcrumbContainer");
breadCrumbContainer.setOutputMarkupId(true);
add(breadCrumbContainer);
final AjaxLink panelLink = new AjaxLink("panelLink") {
@Override
public void onClick(final AjaxRequestTarget target) {
replaceContentPanel(getOverviewPanel(), target);
}
@Override
public boolean isVisible() {
return !(content instanceof OverviewPanel);
}
};
breadCrumbContainer.add(panelLink);
panelLink.add(new Label("panelLabel", new Model<String>() {
@Override
public String getObject() {
//some dynamic content for example:
return contentPanel.getClass().getName();
}
}));
}
public void replaceContentPanel(final Component replacer, final AjaxRequestTarget target) {
content.replaceWith(replacer);
content = replacer;
if (target != null) {
target.add(contentContainer);
target.add(breadCrumbContainer);
}
}
The Home and Page Label
are easy. The one for Panel needs to be updated everytime I updated the content Panel
of the WebPage
. I was sure that the target.add(breadCrumbContainer);
line was going to do this. However it is empty. The Label shows nothing.
I was hoping to find the answer - which is probably obvious - while writing up the question, but it still eludes me, so I am hoping someone here spots my mistake.