【问题标题】:apache wicket - add PagingNavigator component to footer panelapache wicket - 将 PagingNavigator 组件添加到页脚面板
【发布时间】:2014-01-03 13:08:06
【问题描述】:

我正在尝试将 Wicket PagingNavigator 添加到我的 Wicket WebPage 的页脚面板中,但与之相关的 PageableListView 位于页面正文中。

我已经建立了一个 Wicket 基本页面,它有一个简单的页脚面板。然后,我创建了一个 WebPage,它扩展了我的基本页面,因此继承了我的页脚面板。

在我的网页上,我添加了一个运行良好的 PageableListView。我的问题是我现在希望为我的 PageableListView 添加一个 PagingNavigator,但我想将 Navigator 添加到我的页脚面板中。

当我调用我的 WebPage 的构造函数时,它的第一个调用是 super(),这反过来会将我的页脚添加到页面中,然后我的 PageableListView 在页脚构造函数已经被调用之后添加。

我尝试通过在页脚中添加一个带有空模型的虚拟 PageableListView 来解决此问题,然后在将 PageableListView 填充到 WebPage 后立即将其更新为我的实际 ListView。但是,看起来我在页脚面板中的 PagingNavigator 仍在静态引用初始虚拟 ListView。有什么想法可以让我的 PagingNavigator 在页脚中引用正确的 PageableListView 吗?

提前感谢任何可以为我指明正确方向的人,让我能够正确地将我的 PagingNavigator 添加到我的页脚面板...

基本页面:

public class BasePage extends WebPage {

private Component footerPanel;


public BasePage() {
    add(footerPanel = new FooterPanel("FooterPanel"));
}

public Component getFooterPanel() {
    return footerPanel;
}
}

页脚面板:

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;
}
}

我的页面:

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

}
}

【问题讨论】:

    标签: listview wicket


    【解决方案1】:

    建议在 onInitialize 方法中而不是在构造函数中添加组件(如您的页脚面板)。通过在 onInitialize 中添加它们,父组件已经是组件树的一部分并完全构建。

    onInitialize 在页面第一次渲染之前在所有组件上反复调用。

    【讨论】:

    • 您好 Nicktar,感谢您的回复。如果我在 BasePage 的 onInitialize 方法中添加页脚面板,我该如何将在 MyPage 中创建的 listView 传递给页脚?
    • 我将创建 PagingNavigator 以及 ListView,因为大多数人阅读代码时都期望它,然后将其添加到 FooterPanel。将行添加到 Panel 到 FooterPanel 中(例如在将 navigatorobject 作为参数的新方法中)还是放入包含 ListView 的 Page 类取决于 FooterPanel 有多少不同的用例...
    猜你喜欢
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2011-08-25
    相关资源
    最近更新 更多