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-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Look at the ZKFiddle Code here
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
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 )editAsked: 2014-09-20 07:56:15 +0800
Seen: 25 times
Last updated: Sep 20 '14