-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
We use a listbox with the parameter checkmark=true and multiple=true. On enabling these settings we get a horizontal bar with the option check multiple rows on our page:
At the moment we want to store our selection of items (items.getSelection()) and while paging from one page to another, we want to display it. Items has a datatype of ListModelList containing objects to display to the user.
This is the use case that i have:
In my .zul file i call the following method:
<listbox model="@load(vm.items)" onselect="@command('select')"/>
In the select @command method i store my current selection:
getItemsSelection().put( getActivePage(), new HashSet(getItems().getSelection()) );
getItemsSelection is a Linked HashMap containing the pagenumber as key and Set as value.
Please note that i use a new HashSet(), since the getItems().getSelections() get cleared after i move to a new page.
Now when i navigate back and forth, if i return to the first page i set the selection manually:
getItems().setSelection( getItemsSelection().get( getActivePage() ) );
I can confirm that i set the 22 previous selected object back again on the listmodellist.
The only thing that i am missing is that my overview of page 1 that it does not show my checkboxes checked.
Can you please help us further?
Kind regards,
Remie
Hi,
I found the issue.
I see that ZK calls this method in AbstractModelList class
public void clearSelection() { if (!this.selection.isEmpty()) { this.selection.clear(); this.fireEvent(4, -1, -1); } }
Which flushes my saved selection.
Please tell me how can i prevent this?
when you switch the active page, Listbox still keeps your selection in the Model. Why do you want to clear the selection when switching to the next page?
which zk version do you use?
I try to simulate your case (in a simplified way) at https://zkfiddle.org/sample/32tfdlr/1-saving-current-selection-with-paging but cannot reproduce the issue you mentioned.
could you provide a reproducible case at zkfiddle?
Hi Hawk,
We are using ZK version 9.6.0.2
I updated the fiddle with my code (use-case):
It seems to be working, as expected. When i switch back to my code base (company application) i try the same strategy for keeping track of the selection, it does not work.
I do not know why, but after running the code (in my company application):
model.setSelection( selection );
In AbstractModelList.class (ZK class) the following method gets executed:
public void clearSelection() { if (!this.selection.isEmpty()) { this.selection.clear(); this.fireEvent(4, -1, -1); } }
This methods removes my previous selection. If i try to debug the method i can only see that the stack is coming from ZK:
Do you have any more ideas?
Kind regards,
Remie
Hi Hawk,
I think i found it.
I can reproduce my issue at:
Notice that i use the setting in my .zul file:
selectedItem="@load(vm.selected")
This causes my listbox to reset its selection. I really need this functionality too. How can i prevent this behaviour?
Since you have controlled the selection with model API like model.setSelection()
, you should not bind on selectedItem
. This binding will change the selected item again based on vm.selected
I fixed the code: https://zkfiddle.org/sample/32tfdlr/4-saving-current-selection-with-paging-remie
Asked: 2023-07-04 21:08:16 +0800
Seen: 13 times
Last updated: Sep 12
ZK Listbox Selectitems issue with Set
How to stop a bug from a listbox?
Cannot Change Listbox Header color & Background
Keyboard navigation in listbox
Can not display data in listbox
listbox with nonSelectabletags inplace new listitem
Input invoice using inline listbox
Change color to hover listitem listbox zk7 + Atlantic Theme
Listbox with autopaging causes constant row flickering
zk listbox getItems() returns null for item.getValue() if not scrolled fully