【问题标题】:Wicket replacing items in ListView检票口替换 ListView 中的项目
【发布时间】:2014-06-21 13:33:46
【问题描述】:

我想在单击按钮时更改列表视图的数据。

这是我目前所做的:

final PageableListView<Users> listview = new PageableListView<Users>("rows", displayList, 10) {
    //....
    protected void populateItem(final ListItem<Users> item) {
        item.add(new Label("username").setOutputMarkupId(true));
        // .. other fields
    }
}

final IndicatingAjaxFallbackLink<MyPanel> sublist = new IndicatingAjaxFallbackLink<MyPanel>("sublist") {
        public void onClick(AjaxRequestTarget target) {
                displayList = // get new list
                listview.setList(displayList);
                target.addChildren(listview, Label.class);
        }
};
add(sublist);

如果新列表的大小与旧列表的大小完全相同,则此方法有效。在任何其他情况下,我都会得到一个

Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

我该如何解决这个问题?

【问题讨论】:

  • 我会将整个列表添加到目标中,例如target.add(listview);。更新部分列表时存在一些已知的 ajax IE 问题。
  • 我已经尝试过了,但列表视图无法替换(据我所知):This component is a repeater and cannot be repainted via ajax directly. Instead add its parent or another markup container higher in the hierarchy.

标签: java listview wicket


【解决方案1】:

因为我无法通过target.add(listview); 更新列表视图,所以我添加了一个WebMarkupContainer,如下所示:

final WebMarkupContainer datacontainer = new WebMarkupContainer("data");
datacontainer.setOutputMarkupId(true);
add(datacontainer);

现在我可以更新onClick 方法:

target.add(datacontainer);

这很好 - 问题解决了。

但是为什么替换孩子不起作用我仍然不清楚

【讨论】:

  • 使用#addChildren() 将所有标签添加到 AjaxRequestTarget。请注意,ListItems 通过来自父母中继器的索引获取它们的模型。列表中没有匹配项的 ListItem 将抛出 IllegalArgumentException。
  • 列表视图的子视图已经从前一个列表中渲染出来,将它们添加到目标将无助于创建新的。
猜你喜欢
  • 1970-01-01
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 2016-06-10
相关资源
最近更新 更多