Table and single selection mode on the book-examples

Hello :slight_smile:

I followed this simple example for my project: http://demo.vaadin.com/book-examples/book/#component.table.selecting.single

Unfortunately, there is a bug. If i click on a row i see the label correctly. But, if i click again on the same row, i see an exception.

Is there a way to avoid the exception at the second click on the same row?
Finally, there is a way to remove the label at the second click?

Thanks

Hi! You are right there is a bug in the example. The problem is that when you click next time the row; it is unselected and thus event.getProperty().getValue() == null which causes that NullPointerException. Easy fix for that would be e.g. (with label removing)


public void valueChange(ValueChangeEvent event) {
   if (event.getProperty().getValue() != null) {
      lastLabel = new Label("Selected item id " + event.getProperty().getValue().toString());
      layout.addComponent(lastLabel);
   } else {
      layout.removeComponent(lastLabel);
   }
}
}

perfect … many thanks for your help :slight_smile:

Fixed the example, thanks for reporting the problem.