Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
TreeTable select / deselect issues
Hi,
There is a treetable. The treetable is initialized like this:
...
trtbMain.setColumnHeader("col1", "Header 1");
trtbMain.setColumnHeader("col2", "Header 2");
trtbMain.setSelectable(true);
trtbMain.setSizeFull();
trtbMain.addContainerProperty("col1", String.class, null);
trtbMain.addContainerProperty("col2", String.class, null);
trtbMain.addExpandListener(this::trtbMainExpandListener);
trtbMain.addItemClickListener(this::trtbMainItemClickListener);
trtbMain.addStyleName("borderless");
...
private void trtbMainItemClickListener(com.vaadin.event.ItemClickEvent itemClickEvent) {
...
}
I want to do some job when an item is selected and another job when the item is deselected. These jobs doesn't have any visual output but there are 2 issues:
1) If I go with itemClickEvent.getItem(); item never becomes null after the first selection. If selected item is reclicked to deselect it, the item remains the same. If another one is clicked, the item becomes the newly clicked item.
2) If I go with trtbMain.getValue(); after the first click on an item, the value is null but item appears to be selected and its row is blue. After the second click on the same item, the value has some value but the item row appears not to be selected.
Am I doing something wrong? How can I handle TreeTable's itemClickListener properly?
Thank you...
Hi,
the ItemClickListener reports a click on an item, and obviously an item cannot be null in any case. I think you need to use the ValueChangeListener - then you should get null from the ValueChangeEvent once you deselect the item (and no other items are selected in case of multi-select).
-tepi
Teppo Kurki: Hi,
the ItemClickListener reports a click on an item, and obviously an item cannot be null in any case. I think you need to use the ValueChangeListener - then you should get null from the ValueChangeEvent once you deselect the item (and no other items are selected in case of multi-select).
-tepi
Thank you Teppo Kurki for your quick response.
I implemented ValueChangeListener and now its behaviour is as expected but ItemClickListener listener's behaviour is still a question in my mind. I'll take a closer look at the listener after a while.
ValueChangeListener is fired when there has been a change in the value - in other words selected rows have changed.
ItemClickListener is fired on any click on an item - it's independent on the selection state / value. In fact you can have item click events for a non-selectable table as well.