tree - strange behaviour of the selected item

Hi all! :slight_smile:

I am facing a problem with the tree class.
I have a tree containing a certain substructure of three different classes. Class A is the top level and contains objects of class B which are also displayed. B objects contain a list of objects of class C shown too.

The tree has an itemClickListener attatched to it because I need to get a notification if a C object is clicked.
And here strange behavior starts:
The first time click at an item the getValue() method of the tree returns null. Only upon the second click (when the background colour switches from blue to white) it works and I get the right class type!
Clicking an other item afterwards the object found by the clickListener is of the type I clicked before, before it flips to the right one…

Is there a way to turn this first step with the blue background off?

The tree’s setImmediate(…) is already set to true!

It would be really great if somebody could help me! :slight_smile:

Thanks very much in advance and have a nice evening!


I don’t know if this post is still relevant, but I just had the same frustrations… I wanted to catch “selection” events on a Tree using the ItemClickListener method, but the selection flipped back everytime, right after I handled the event. If I did not use an ItemClickListener, everything was all right.

After debugging the Vaadin source, googling a lot and finding this post, I decided to look for another method to catch selection changes. Actually I do not care about clicks, but only selection changes. I found this solution to be perfect for me:

tree.addListener( Field.ValueChangeEvent.class, this, “handleTreeValueChange” );

And defined the above mentioned method on the listening class:

public void handleTreeValueChange( Field.ValueChangeEvent event ) {
if ( ( panel == null ) || panel.isAvailable( cmdSelectionAllowed ) ) {
Property property = event.getProperty();
Object itemId = property.getValue();

The property is the Tree instance itself and the value is the just selected item’s ID.