0

Combobox in grid row trouble

asked 2013-08-28 17:13:45 +0800

MaxRozenson gravatar image MaxRozenson
29 3

updated 2013-08-28 17:17:24 +0800

Hi! I'm tying to reproduce combobox inline editing feature, like in Inline Editing (Grid) demo. Here is part of my view:

<grid id="hypothesisMainGrid"
                                model="@load(vm.curUserHyps)"
                                mold="paging" pageSize="4" 
                                pagingPosition="bottom" hflex="1">
                            <columns>
                                <column label="Номер" />
                                <column label="Статус" />
                            </columns>
                            <template name="model">
                                <row>
                                    <label  value="@load(each.hypId)" width="99%" />
                                    <combobox  
                                                readonly="true" model="@load(vm.hypStatusList)"
                                                selectedItem="@bind(each.hypothesisStatus)"
                                                 hflex="1"
                                                inplace="true">
                                                <template
                                                    name="model">
                                                    <comboitem
                                                        label="@load(each.name)" value="@load(status)" />
                                                </template>
                                    </combobox>         
                                </row>
                            </template>
                        </grid>

The trouble is that selecting some item in combobox causes all items in grid model to change correspondig field (hypothesisStatus). Please see screen http://i.imgur.com/zqdYzXb.jpg (here)). The same happens with listbox.

Why this can happen? I use ZK 6.5.2 CE. Thanks in advance, Max

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted
1

answered 2013-08-29 11:21:29 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2013-08-29 11:22:42 +0800

Hi Max,

this can happen, when you use a ListModel for vm.hypStatusList e.g.

private ListModelList<Status> hypStatusList = 
  new ListModelList<Status>(Arrays.asList(
    Status.NEW, Status.PENDING, 
    Status.IN_PROGRESS, Status.DONE));

In this case the listmodel of status will be reused for all items in the list. And as ListModel keeps the selected item, it will store it to all its usages.

To avoid that use a pure list instead, which will be wrapped by a separate ListModel for each item in your grid automatically.

private List<Status> hypStatusList = 
  new ArrayList<Status>(Arrays.asList(
    Status.NEW, Status.PENDING, 
    Status.IN_PROGRESS, Status.DONE));

If this list takes a lot of memory (or many copies of it would), you can use a live ListModel instead to reduce memory footprint.

public ListModel<Status> getHypStatusList() {
  return new ListModelList<Status>(hypStatusList, true);
}

Like that the hypStatusList only exists once, and is wrapped by a separate ListModel for each item in the grid, not sharing the state.

Robert

link publish delete flag offensive edit
0

answered 2013-08-30 14:03:24 +0800

MaxRozenson gravatar image MaxRozenson
29 3

Robert, thanks a lot for such detailed explanation, it works!

link publish delete flag offensive 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
3 followers

RSS

Stats

Asked: 2013-08-28 17:13:45 +0800

Seen: 50 times

Last updated: Aug 30 '13

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