【问题标题】:Wicket - how to refresh single row in a table with ajaxWicket - 如何使用 ajax 刷新表中的单行
【发布时间】:2020-12-16 12:18:13
【问题描述】:

在我的 wicket 应用程序中,我有一个表格,其中一行的每一列由一个 bean 描述。其中一列包含一个 ajax 组件,该组件可以更改 bean 中的值,从而更改其他列中显示的值。

如何在不重新加载整个表的情况下更新这些列?

现在我使用以下代码:

public static <T> void refreshTableRow(AjaxRequestTarget target, Item<ICellPopulator<T>> columnItem) { 
    for (Component component : columnItem.getParent()) {
        if (component instanceof Item) {
            ((Item<?>) component).stream()
                    .filter(Component::getOutputMarkupId)
                    .forEach(target::add);
        }
    }
}

但为了让这段代码正常工作,我必须为在IColumn#populateItem 中创建的每一列的根组件设置outputMarkupId(true)

还有其他方法吗?

【问题讨论】:

  • 您使用哪个组件来制作表格?数据表?!
  • 是的,我使用 DataTable

标签: java wicket


【解决方案1】:

覆盖DataTable#newRowItem() 并返回一些具有outputMarkupId = true 的自定义Item 实现。

public class MyRow<T> extends Item<T> {
   public MyRow<T>(String id, int index, IModel<T> model) {
     super(id, index, model);

     setOutputMarkupId(true);
   }
}

然后在你的 Ajax 回调方法中做:

ajaxRequestTarget.add(findParent(MyRow.class));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2011-09-14
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 2013-12-03
    相关资源
    最近更新 更多