问题
I use Vaadin (6.7.4) and this table (it is on a modal window) does not update the view.
First it was created with generated columns, but I read that it has problems with table update, so I switched back to normal table, but still no refresh.
Updatedata is called by button click event on the panel
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");
}
Edit: turned out problem is not about this code, but this class was instantiated 2 times, so I had different instances; the one i am updating and the one I see.
回答1:
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.
回答2:
Try changing the main window to static:
public static Window win = new Window("Window");
setMainWindow(win);
This should help.
来源:https://stackoverflow.com/questions/10910302/vaadin-table-does-not-update-no-matter-what-i-try