Search code examples
vaadinvaadin7

How determine if a Vaadin table row clicked in has been selected or deselected?


Following a user clicking in a row in a Vaadin 7 table, how can I tell if the row has been selected or deselected - clicking in a selected row deselects the row - (since there is also a column of checkboxes which needs to kept in synch)?

When I tried table.getValue() in an ItemClickListener, this returned null if the row is selected and the item id if the row is deselected - i.e. the opposite of what I would have expected?

table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
  @Override
  public void itemClick(ItemClickEvent event) {

    // how tell if row has been selected or deselected?
    Object idx = table.getValue();
  }
});

Thank you, Steve


Solution

  • In the Table api you can use the getValue() method, which results the selected rows.

    Depending if in multiselct mode or not, you can then deduce what happens.