tree non-selectable items

Hi All,

I was just wondering if it is possible to set non-selectable to some of the items on the tree?

So for example, I have something like that

Category A
- a
- b
- c

Category B
- d
- e

I want a,b,c, d,e to be all selectable, but I also want Category A and Category B to be non-selectable.

Please advise on what I should do.

Hi,

there is currently no way to achieve this in any Vaadin selection components. You can implement this functionality by e.g. adding a ValueChangeListener for the Tree and within it checking the selected value. If the value is one of the items not allowed for selection you can just de-select the selected item. Downside in this approach is that the user will probably see the “non-selectable” item selected for a short while.

Another option would be to extend/modify the Tree component on the client side to create this functionality.


Tepi

You can achieve this behaviour by setting the tree to nonselectable and implementing an ItemClickListener where you check, whether the clicked item is selectable or not and do the tree.setValue(itemId) there. This has the downsize that only mouse input is available on the tree.

Thanks a lot for your suggestions. I may just leave it alone or try out your ideas.

I have a similar problem regarding tables.

I used the ItemClickListener to prefent selecting a row if I don’t want to.

So I set the value of the table via “setValue(itemId)” manually.

But the problem is how do I tell the table that the row which is selected should be rendered as a selected row?