Vaadin table.select(itemId) is not working

2019-07-25 14:14发布

问题:

I have a table bind to a SQLContainer and a insert button (that insert a row in the table)

When the button is clicked it execute the below code of the listener:

Object itemId = table.addItem();
container.getContainerProperty(itemId, "cedula").setValue(cedulaS);

try {
    container.commit();
    table.select(itemId);
catch (UnsupportedOperationException e) { //bla }

The row is properly inserted BUT I want that automatically the row be selected but the select method is not working any idea?

EDIT:

The select(ItemId) is working and its select the row BUT for some reason the commit line make that the select(ItemId) didnt works. I think is because itemId is a temporary row, so when the commit is execute it disappear o lose its values.

回答1:

This thread has the answer, thanks to @Teppo Kurki

https://vaadin.com/forum#!/thread/4268146

The problem is that itemId is a temporal row id so when the commit is executed iy changed the row id, so it must be implemented the below listener:

container.addRowIdChangeListener(new QueryDelegate.RowIdChangeListener() {
  void rowIdChange(QueryDelegate.RowIdChangeEvent event) {
      table.select(event.getNewRowId());
   }
});

Ant we now can delete the table.select(itemId); in the initial post