0

ZK ListBox Bug on Select All with Check Mark true

asked 2014-09-20 07:56:15 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Look at the ZKFiddle Code here

  1. Run the code.
  2. Click Select All Button
  3. All the Records will be selected.
  4. Now try to click Next button in the pagination. It will not move to next set of records. is this bug ?
delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2014-09-20 09:58:25 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Senthilchettyin,

I performed a number of modifications to your code so it can work as expected:

The zul file:

<window title="Example for ZK MVVM List Box" width="500px"
   apply="org.zkoss.bind.BindComposer"
 viewModel="@id('vm') @init('pkg$.ListBox2')">
 <label value="You are using: ${desktop.webApp.version}" />
    <separator></separator>
 <listbox id="personsLstbx" model="@load(vm.allPersons)" checkmark="true" mold="paging" pageSize="3"
       multiple="true"
     selectedItems="@bind(vm.selectedPersons)">
       <listhead sizable="true">
         <listheader label="First Name" sortDirection="ascending"
             sort="auto(firstName)" />
            <listheader label="Last Name" sort="auto(lastName)" />
            <listheader label="Email" sort="auto(email)" />
       </listhead>
       <template name="model" var="p1">
          <listitem>
                <listcell label="@load(p1.firstName)" />
              <listcell label="@load(p1.lastName)" />
               <listcell label="@load(p1.email)" />
          </listitem>
       </template>
   </listbox>
    <button label="Select All"
     onClick="@command('onSelectAll')">
 </button>
</window>

And the java class:

package pkg$;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Listbox;

public class ListBox2  {

  @Wire
  private Listbox personsLstbx;

  private List<person> allPersons = new ArrayList<person>();
  private person selectedPerson;
  private List<person> selectedPersons;

  @AfterCompose
  public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {

      Selectors.wireComponents(view, this, false);

  }

    public person getSelectedPerson() {
     return selectedPerson;
  }



   public void setSelectedPerson(person selectedPerson) {
      this.selectedPerson = selectedPerson;
   }

   public List<person> getSelectedPersons() {
        return selectedPersons;
 }

   public void setSelectedPersons(List<person> selectedPersons) {
        this.selectedPersons = selectedPersons;
 }

   public List<person> getAllPersons() {
     return allPersons;
  }

   public void setAllPersons(List<person> allPersons) {
      this.allPersons = allPersons;
   }

   public ListBox2() {

     allPersons.add(new person("John 1", "James", "[email protected]"));
     allPersons.add(new person("Taylor 2", "Harris", "[email protected]"));
     allPersons.add(new person("Allen 3", "Scott", "[email protected]"));
       allPersons.add(new person("John 4", "James", "[email protected]"));
     allPersons.add(new person("Taylor 5", "Harris", "[email protected]"));
     allPersons.add(new person("Allen 6", "Scott", "[email protected]"));
       allPersons.add(new person("John 7", "James", "[email protected]"));
     allPersons.add(new person("Taylor 8", "Harris", "[email protected]"));
     allPersons.add(new person("Allen 9", "Scott", "[email protected]"));


    }

   @Command
   @NotifyChange({"selectedPersons"})
      public void onSelectAll()
    {
      this.selectedPersons = new ArrayList<person>();

        for (person p: allPersons) {
            selectedPersons.add(p);
        }

    }

   // inner class
  public class person {
       private String firstName;
       private String lastName;
        private String email;

       public person(String firstName, String lastName, String email) {
            this.firstName = firstName;
         this.lastName = lastName;
           this.email = email;
     }

       public String getFirstName() {
          return firstName;
       }

       public void setFirstName(String firstName) {
            this.firstName = firstName;
     }

       public String getLastName() {
           return lastName;
        }

       public void setLastName(String lastName) {
          this.lastName = lastName;
       }

       public String getEmail() {
          return email;
       }

       public void setEmail(String email) {
            this.email = email;
     }

   }
}

The problem was that there was a conflict when you set both selectedItem, and selectedItems (You only need selectedItems).

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

Thank you. But still it is ZK BUG ? Because in some cases, i need both selectedItem and SelectedItems

Senthilchettyin ( 2014-09-20 13:27:57 +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

Follow
1 follower

RSS

Stats

Asked: 2014-09-20 07:56:15 +0800

Seen: 25 times

Last updated: Sep 20 '14

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