Hi,
I spent the last couple of hours thinking about the following problem:
I have a DataModel (basically Java classes with some Lists) and several Vaadin tables that displays the data. The data is modified by different Vaadin elements. Here comes my problem:
How to update all depending Vaadin tables after some data is modified?
Here’s a basic example code:
public class Demo extends VerticalLayout {
private DataStructure data = new DataStructure("John", "Maria", "Steve");
private Table table = new Table("Names");
public Demo() {
NativeButton addButton = new NativeButton("Add Name");
addButton.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
data.addName("Linda");
refreshTable();
}
});
this.addComponent(table);
this.addComponent(addButton);
}
public void refreshTable() {
IndexedContainer container = new IndexedContainer();
Item item = null;
container.addContainerProperty("Name", String.class, null);
for (String name : data) {
item = container.getItem(container.addItem());
item.getItemProperty("Name").setValue(name);
}
table.setContainerDataSource(container);
}
}
As you can see I have to manually call refreshTable(); In a more complex scenario I would have to call refreshTable() for all of my different tables.
The question is: How to design a better and more generic solution for this problem?
May it is possible to work with Listeners?