# Multiselect tree will unselect hidden items

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 retag edit

Sort by » oldest newest most voted

cor3000
4332 1 7

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)

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?

( 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.

( 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

( 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/)

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

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

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

cor3000
4332 1 7

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.

Regards,

Robert

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

( 2017-09-08 16:09:47 +0800 )edit
[hide preview]