java - 无论我如何尝试,Vaadin 表都不会更新

标签 java gwt vaadin

我使用 Vaadin (6.7.4),并且此表(位于模式窗口上) 不会更新 View 。

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

通过面板上的按钮点击事件调用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");
}

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

最佳答案

这是一个完整的 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");
}
}

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

关于java - 无论我如何尝试,Vaadin 表都不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10910302/

相关文章:

java - Eclipse java.lang.ClassNotFoundException : com. google.gwt.dev.About

java - OSX 上的 Elasticsearch——Java

GWT 与 MVP : add the same presenter to one container several times

java - 当前 java 进程的错误/输出流

gwt - Requestfactory 克隆代理到新上下文

java - Vaadin 表未实时更新

java - 列表中的点赞总数

java - Vaadin 7 在组件之间触发自定义事件

java - 为什么更改时 JComboBox 上的 itemStateChanged 会被调用两次?

Java 8 流,为什么要编译第 2 部分……或者什么是方法引用,真的吗?