有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Wicket如何使用ajax刷新表中的单行

在我的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)

还有别的办法吗


共 (1) 个答案

  1. # 1 楼答案

    重写DataTable#newRowItem()并返回一些具有outputMarkupId = true的自定义项实现

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