2012-06-06 54 views
2

我使用Vaadin(6.7.4)和此表(它在模态窗口上)不更新视图。无论我尝试什么,Vaadin Table都不会更新

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

的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倍,所以我有不同的情况;我正在更新的那个和我看到的那个。

回答

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

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

+0

谢谢,但这是所有与表相关的代码,任何建议我应该在哪里检查问题? – Spring

+1

对不起,但实际上不可能在没有看到其他代码的情况下推断出问题。然而,疯狂的猜测是:每次updateData()后都会调用createTable()方法? – hezamu

0

尝试改变主窗口静态:

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

这应该帮助。

相关问题