Reputation: 325
I am attempting to add a Wicket PagingNavigator to a footer panel in my Wicket WebPage but the PageableListView it relates to is in the body of the page.
I have built a Wicket base page which has a simple footer panel. I have then created a WebPage that extends my base page and therefore inherits my footer panel.
On my WebPage I have added a PageableListView which is working perfectly. My question is I now wish to add a PagingNavigator for my PageableListView but I want to add the Navigator to my footer panel.
When I call the constructor of my WebPage it's first call is super() which in turn will add my footer to the page, then my PageableListView is added later after the footer constructor has already been called.
I tried to work around this by adding a dummy PageableListView to my footer with an empty model and then updating the PageableListView to my actual ListView as soon as it has been populated in the WebPage. However, it looks like my PagingNavigator in the footer panel is still statically referencing the initial dummy ListView. Any ideas how I can get the correct PageableListView to be referenced by my PagingNavigator in the footer?
Thanks in advance to anyone that can point me in the right direction to allow me to add my PagingNavigator to my footer panel correctly...
Base Page :
public class BasePage extends WebPage {
private Component footerPanel;
public BasePage() {
add(footerPanel = new FooterPanel("FooterPanel"));
}
public Component getFooterPanel() {
return footerPanel;
}
}
Footer Panel :
public class FooterPanel extends Panel {
private PageableListView listView = new PageableListView("dummy", new Model(), 1) {
@Override
protected void populateItem(ListItem listItem) {
}
};
public FooterPanel(String id) {
super(id);
add(new PagingNavigator("navigator", listView));
}
public void setListView(PageableListView listView) {
this.listView = listView;
}
}
MyPage :
public class MyPage extends BasePage {
public MyPage() {
super();
MyModel model = new MyModel();
PageableListView listView = new PageableListView<IModel>("list", model, 5) {
@Override
protected void populateItem(ListItem item) {
final DomainObject object = (DomainObject) item.getModelObject();
item.add(new Label("label", object.getSomething()));
}
};
add(listView);
FooterPanel footer = (FooterPanel)this.getFooterPanel();
footer.setShiftList(shiftList);
}
}
Upvotes: 0
Views: 283
Reputation: 5575
It is advisable to add Components (like your Footer Panel) in the onInitialize method instead and not in the constructor. By adding them in onInitialize the parent component is already part of the component tree and fully constructed.
onInitialize is called recusivly on all components before the first render of the page.
Upvotes: 1