Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin table row change best practice

Tags:

vaadin

What is the best way to replace a table row in Vaadin (6 and 7)? I use BeanItemContainer. The bean is an entity and has changed (not the ID).

I think this cause unnecessary method invocation and/or object creation:

table.removeItem( item );
table.addItem( item );
like image 649
Krayo Avatar asked Oct 21 '22 02:10

Krayo


1 Answers

As I know, the best pratice is:

BeanItemContainer<DataModel> tableDataSource =  new BeanItemContainer<>(DataModel.class);
table.setContainerDataSource(tableDataSource);

When you want to replace a row, just replace the data of this row in tableDataSource:

tableDataSource.removeItem(item);
tableDataSource.addItem(item);

The difference between your code and mine is:

  • In your code, you replace the row (it means the row is removed from the table and then a new row will be added to table).
  • In my example, I just replace the data of row.

Hope it helps

like image 92
Nhat Nam NGUYEN Avatar answered Oct 25 '22 20:10

Nhat Nam NGUYEN