无论我尝试什么,Vaadin Table都不会更新

时间:2012-06-06 07:59:55

标签: java gwt vaadin

我使用Vaadin(6.7.4),此表(它位于模态窗口上)不会更新视图。

首先它是使用生成的列创建的,但我读到它有表更新的问题,所以我切换回普通表,但仍然没有刷新。

通过面板上的按钮点击事件调用Updatedata

final Table table = new Table();
final IndexedContainer ic=new IndexedContainer();

public 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 addItems(Table table) {
    for (String s : createdNames) {
        ic.addItem(s);
        ic.getItem(s).getItemProperty("Name").setValue(s);
        ic.getItem(s).getItemProperty("Edit").setValue("Edit");
        ic.getItem(s).getItemProperty("Delete").setValue("Delete");
    }

}

public void updateData() {      
    IndexedContainer c=(IndexedContainer) table.getContainerDataSource();
    c.removeAllItems();
    c.addItem("myname");
    c.getContainerProperty("myname", "Name").setValue("Mr.X");
    table.setContainerDataSource(c);
    table.refreshRowCache();
    table.requestRepaint();
    System.out.println("see the output but no update on table");
}

编辑:原来问题不在于这个代码,但这个类被实例化了2次,所以我有不同的实例;我正在更新的那个和我看到的那个。

2 个答案:

答案 0 :(得分:3)

这是一个完整的Vaadin应用程序:

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

问题似乎是代码中的其他地方。顺便说一句,在未来你应该从头开始创建一个全新的应用程序来隔离问题,并验证它是你认为的位置。

答案 1 :(得分:0)

尝试将主窗口更改为静态:

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

这应该有所帮助。

相关问题