0

Ordering Issue in "selectedItems" in listbox component

asked 2012-12-14 11:03:59 +0800

biswajitdas gravatar image biswajitdas
36

I am facing an issue in the ordering of items given by selectedItems of listbox components. The property "selectedItems" in component listbox given the selected items in HashSet i.e. in random order. But i need it in LinkedHashSet. Is there any way to get the selectedItems in the ordered way or in LinkedHashSet with related to the displayed List which is senderList in my case?



Below is my zul file: list.zul
<window apply="org.zkoss.bind.BindComposer"
	viewModel="@id('vm') @init('List1')">

	<listbox model="@bind(vm.senderList)" multiple="true"
		selectedItems="@save(vm.selectedSenders)" height="300px">
		<listhead>
			<listheader label="Sender"></listheader>
		</listhead>
		<template name="model" var="item">
			<listitem value="${item }">
				<listcell label="@load(item)"></listcell>
			</listitem>
		</template>
	</listbox>
	<div style="text-align:right; padding:5px;">

		<button mold="trendy" label="Submit"
			onClick="@command('submit')" />

	</div>
</window>

And my Java Code is as:
List1.java

public class List1 {

	private List<String> senderList;

	private Set<String> selectedSenders;

	public List<String> getSenderList() {
		if (senderList == null) {
			senderList = new ArrayList<String>();
			senderList.add("Sender1");
			senderList.add("Sender2");
			senderList.add("Sender3");
			senderList.add("Sender4");
			senderList.add("Sender5");
			senderList.add("Sender6");
			senderList.add("Sender7");
			senderList.add("Sender8");
			senderList.add("Sender9");
			senderList.add("Sender10");
		}
		return senderList;
	}
	public void setSenderList(List<String> senderList) {
		this.senderList = senderList;
	}

	public Set<String> getSelectedSenders() {
		return selectedSenders;
	}

	public void setSelectedSenders(Set<String> selectedSenders) {
		this.selectedSenders = selectedSenders;
	}

	@Command
	public void submit() {
		System.out.println("Printing Selected Senders...");
		for (String sender : selectedSenders) {
			System.out.println(sender);
		}
	}
}

I/p: Select Sender 2,3,4,5 and click on submit
O/p: on console: It prints Sender 5,3,4,2

I want the o/p to be as "Sender 2,3,4,5".

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-12-19 12:16:48 +0800

biswajitdas gravatar image biswajitdas
36

Why selectedItems is taken as HashSet in Listbox component? It should be of LinkedHashSet type. Is this was any kind of bug in Listbox component?

link publish delete flag offensive edit

answered 2012-12-19 12:59:42 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

please post a bug at http://tracker.zkoss.org/ with your example code.

link publish delete flag offensive edit

answered 2012-12-20 06:17:12 +0800

biswajitdas gravatar image biswajitdas
36

Thanks,

Raised the bug below:

http://tracker.zkoss.org/browse/ZK-1529

link publish delete flag offensive edit
Your reply
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

Follow

RSS

Stats

Asked: 2012-12-14 11:03:59 +0800

Seen: 70 times

Last updated: Dec 20 '12

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