-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
Robert, thanks a lot for such detailed explanation, it works!
Asked: 2013-08-28 17:13:45 +0800
Seen: 50 times
Last updated: Aug 30 '13