Wicket – how to refresh single row in a table with ajax



In my wicket application I have a table where each column of a row described by one bean. One of the column contains an ajax component that can change the values in the bean and therefore the values displayed in other columns.

How can I update these columns without reloading the whole table?

Now I use the following code:

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

But for the proper work of this code I have to set outputMarkupId(true) for the root component of each column, created in IColumn#populateItem.

Is there any other way to do this?

Answer

Override DataTable#newRowItem() and return some custom Item implementation that has 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);
   }
}

Then in your Ajax callback method do:

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


Source: stackoverflow