Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-1529

Ordering Issue in "selectedItems" in listbox component

XMLWordPrintable

    • None

      "selectedItems" in Listbox component is HashSet Type, it should be LinkedHashSet Type. 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.

      Below is my zul file: list.zul
      [code]
      <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>
      [/code]

      And my Java Code is as:
      List1.java

      [code]
      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); }

      }
      }
      [/code]

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

      For more references:

      http://www.zkoss.org/forum/listComment/21346-Ordering-Issue-in-selectedItems-in-listbox-component

            Unassigned Unassigned
            biswajitdas biswajitdas
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: