Vaadin Table does not update no matter what I try

旧街凉风 提交于 2019-12-06 05:04:09

Here is a complete Vaadin application that works:

public class TableTest extends Application {
final Table table = new Table();
final IndexedContainer ic = new IndexedContainer();

@Override
public void init() {
    setMainWindow(new Window("Window"));
    createTable();
    getMainWindow().addComponent(table);
    getMainWindow().addComponent(
            new Button("Click me", new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    updateData();
                }
            }));
}

public void createTable() {
    table.setImmediate(true);
    table.setEnabled(true);
    ic.addContainerProperty("Name", String.class, null);
    ic.addContainerProperty("Edit", Button.class, null);
    ic.addContainerProperty("Delete", Button.class, null);
    table.setContainerDataSource(ic);
}

public void updateData() {
    ic.removeAllItems();
    ic.addItem("myname");
    ic.getContainerProperty("myname", "Name").setValue("Mr.X");
    System.out.println("see the output but no update on table");
}
}

It seems that the problem is somewhere else in your code. By the way, in the future you should create a completely new application from scratch to isolate the problem and validate that it is where you think it is.

Daniccan

Try changing the main window to static:

public static Window win = new Window("Window");
setMainWindow(win);

This should help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!