Demo list group

asked 2015-01-02 23:16:37 +0800

wigberto gravatar image wigberto
52 4

I am testing 'demo list group' (http://www.zkoss.org/zkdemo/listbox/list_group) example of zk live demo and when I do a complete selection of all groups and debug code do I just get the data from the first group and not all groups. If I select each group separately, it works fine, but if I select all groups receive only data from the first group although visually have selected all.

    public void selectGroup(@BindingParam("data") Object data) {
        if(data instanceof FoodGroupsModel.FoodGroupInfo) {
            FoodGroupsModel.FoodGroupInfo groupInfo = (FoodGroupsModel.FoodGroupInfo)data;
            int groupIndex = groupInfo.getGroupIndex() ;
            int childCount = groupModel.getChildCount(groupIndex);
            boolean added = groupModel.isSelected(groupInfo);
            for(int childIndex = 0; childIndex < childCount; childIndex++) {
                Food food = groupModel.getChild(groupIndex, childIndex);
                if(added) {
                } else {

<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('demo.listbox.list_group.ListGroupViewModel')">
    <listbox model="@load(vm.groupModel)" height="400px" checkmark="true"
        onSelect="@command('selectGroup', data=event.reference.value)" multiple="true"
        <!-- Make Grouping item selectable-->
        <custom-attributes org.zkoss.zul.listbox.groupSelect="true" />
            <listheader width="160px" sort="auto(Category)" label="Category" />
            <listheader width="140px" sort="auto(Name)" label="Name" />
            <listheader hflex="1" sort="auto(TopNutrients)" label="Top Nutrients" />
            <listheader hflex="1" align="center" sort="auto(DailyPercent)" label="% of Daily" />
            <listheader hflex="1" align="center" sort="auto(Calories)" label="Calories" />
            <listheader width="140px" sort="auto(Quantity)" label="Quantity" />        

Thank you.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-01-04 09:04:37 +0800

Darksu gravatar image Darksu
1991 1 4

Hello wigberto,

Indeed the controller has to be updated in case that all groups are selected by changing the selectGroup method and taking into account the number of groups.

Thanks for the finding.

Best Regards,


link publish delete flag offensive edit


And how can I fix it? Thank you.

wigberto ( 2015-01-04 22:11:27 +0800 )edit

answered 2015-01-05 03:02:08 +0800

hawk gravatar image hawk
2400 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2015-01-05 03:05:24 +0800


I have run the demo under ZK 7.0.4. I found that I can get 35 objects, all selected items, in groupModel.getSelection() after clicking check-all checkbox on listheader.

When clicking check-all checkbox, Listbox adds all model object of currently selected item into its selection by addSelection(), so you get all selected object by calling GroupsModelArray.getSelection(). But that selection includes FoodGroupInfo, Integer - subtotal of each group, and data object - Food you can filter them by instanceof Food to get data object only.

If you want to implement your own selectAll to make selection contain data object (Food) only, you can add command binding on onCheckSelectAll and add all data objects into GroupModel's selection.

<listbox onCheckSelectAll="@command('selectAll')">

 public void selectAll(){
link publish delete flag offensive edit


Thank you hawk.

wigberto ( 2015-01-14 08:30:09 +0800 )edit

@wegberto, could you mark this as an answer?

hawk ( 2015-01-14 08:54:27 +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

1 follower



Asked: 2015-01-02 23:16:37 +0800

Seen: 37 times

Last updated: Jan 05 '15

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