Multiselect tree will unselect hidden items

asked 2017-09-07 16:10:07 +0800

Raw gravatar image Raw
52 3

I'm using a Tree with a DefaultTreeModel<string>. I have set checkmark=true (in the ZUL) and multiselect=true (in the code). Initially, I select all items via myTreeModel.setSelection(Collection<treenode>). The tree shows up with all first-level nodes closed (hidden children). When I click down the tree, all nodes show up as selected, as I expected. But if I select any node, all previously selected nodes that have never been opened yet on the GUI will be deselected! Only those nodes which are visible or have been visible once will keep their 'selected' status.

I can track this behaviour with the onSelect handler. On the first select, event.getPreviousSelectedObjects() will return all selected nodes from the tree model. But ev.getSelectedObjects(), or myModel.getSelection() will only return selected nodes which are currently visible, or which have been visible at least once.

So I suspect that event.getSelectedObjects() only returns selected objects from the Tree view, not from the model.

Does anybody know a functioning workaround for this? Or better: a fix?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-09-11 02:40:04 +0800

cor3000 gravatar image cor3000
5399 2 7
ZK Team

updated 2018-04-20 15:33:57 +0800

Now I see your point ... and I see the inconsistency which I'll post as a separate issue for investigation/fixing.

However as of your current code it looks you are doing something unnecessary. The DefaultTreeModel (implementing Selectable/TreeSelectableModel) will already synchronize the current selection automatically (without calling treeModel.setSelection), which is a huge benefit about using a model based approach (also the opened state it managed in a similar fashion).

So if you do nothing the current selection (treeModel.getSelection()) will automatically be up-do-date as in the updated example.

I hope this will help as a workaround for now.

UPDATE: posted ZK-3738 -> FIXED (will be in 8.5.2)

link publish delete flag offensive edit


Hi Robert, thanks for the workaround. It works in version 7.0.8 (which I am not allowed to download) or version 8. In version 7.0.3 (free download), treeModel.getSelection() also shows the same bug after the second click on the tree. Will there be incompatibilities if I switch to version 8?

Raw ( 2017-09-11 23:05:20 +0800 )edit

By the way: the update which seems unnecessary was to reflect possibly concurrent changes in the database by other users, but I can leave this away for now.

Raw ( 2017-09-11 23:07:59 +0800 )edit

Unless you are using the MVVM pattern with form-binding I am not aware of any breaking changes. However since 7.0.3 several bugs fixes and smaller features have been implemented so there will be some changes, that might affect your application. You won't know unless you try ;) Robert

cor3000 ( 2017-09-12 09:08:07 +0800 )edit

Also check-out the release notes: https://www.zkoss.org/product/zk/releasenote/8.0.0https://www.zkoss.org/product/zk/releasenote/8.0.1 ... (and 8.5 is on the horizon, so maybe wait for that before upgrading, you can try the current state now https://www.zkoss.org/download/freshly/)

cor3000 ( 2017-09-12 09:11:17 +0800 )edit

Thanks a lot for the help. I upgraded to, no issues so far (except for another bug of my own that was tolerated by 7.0.2 but complained about by Your workaround has solved my issue.

Raw ( 2017-09-14 13:54:35 +0800 )edit

answered 2017-09-08 11:40:00 +0800

cor3000 gravatar image cor3000
5399 2 7
ZK Team

updated 2017-09-08 11:45:04 +0800

Hi Raw,

I tried to reproduce the problem in this zkfiddle. However on my side (even when using the old version 7.0.2) the selection state of all nodes (hidden or visible) remains as expected.

Might be that I am missing a detail in your description or your implementation is slightly different.

So if this working example doesn't help, feel free to adjust it to reproduce your problem and post the updated link so I can have a second look.



link publish delete flag offensive edit


Many thanks for the quick reply. The problem is the onSelect handler. event.getPreviousSelectedObjects() returns all nodes correctly, but event.getSelectedObjects() only returns visible objects. See this example: http://zkfiddle.org/sample/3djug99/3-Hidden-selected-tree-nodes-ignored-in-onSelect

Raw ( 2017-09-08 16:09:47 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2017-09-07 16:10:07 +0800

Seen: 19 times

Last updated: Apr 20 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More