First time here? Check out the FAQ!
Hello,
i don't understand why these comboboxes update all together at the same time. This is an example..
VM:
package main;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zul.ListModelList;
public class MultipleComboVM {
private ListModelList<String> allDocs = new ListModelList<String>();
private ListModelList<String> categories = new ListModelList<String>();
@Init
public void init() {
for(int i=1; i<4; i++) {
allDocs.add("doc" + i);
categories.add("cat" + i);
}
}
public ListModelList<String> getAllDocs() {
return allDocs;
}
public void setAllDocs(ListModelList<String> allDocs) {
this.allDocs = allDocs;
}
public ListModelList<String> getCategories() {
return categories;
}
public void setCategories(ListModelList<String> categories) {
this.categories = categories;
}
}
ZUL page:
<?page title="" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="" border="normal" viewModel="@id('vm') @init('main.MultipleComboVM')" height="100%">
<borderlayout style="border: 2px solid red; height: 100%; ">
<west id="w" width="20%" border="0" splittable="true" autoscroll="true" flex="true" collapsible="true" >
<div fulfill="self.onCreate">
<div children="@load(vm.allDocs) @template('children')">
<template name='children'>
<groupbox mold="3d">
<caption>
<combobox model="@load(vm.categories) @template('categories')" onClick="event.stopPropagation()"
selectedItem="@bind(each)">
<template name="categories">
<comboitem label="@load(each)" value="@load(each)"></comboitem>
</template>
</combobox>
</caption>
<div children="@load(vm.allDocs) @template('thumbnails')" >
<template name="thumbnails">
<label value="@load(each)"></label>
</template>
</div>
</groupbox>
</template>
</div>
</div>
</west>
</borderlayout>
</window>
</zk>
It's a really simple example but if i select an item on the first combobox, all the comboboxes update with that value, but only the first String
was modified (which is the correct behaviour). It seems like @load(each)
is not working properly here but I guess i'm missing something.
Can someone show me where is the problem here?
ZK Version is: 8.0.2.2
Thank you
EDIT: The problem seems to be related to ListModelList, if i use ArrayList this doesn't happen.
Seems you already found the cause. That's exactly the correct/expected behavior, since the ListModelList
implements the Selectable
interface it will keep track of the current selected item, if the same listModel instance is applied to multiple comboboxes they will all synchronize on the current selection.
So one way you already found is to use ArrayList
which does not implement Selectable
so the selection is not synchronized. (ZK will wrap this Arraylist into a new ListModelList for each combobox keeping the selection separate)
No need to worry this is all working fully 'normal'. Using ArrayList
is a valid decision if the same items should be reused between multiple comboboxes but the selection needs to be kept separate.
I took the freedom to update your example and remove a few unnecessary things (E.g. a list of Strings doesn't need a comboitem template. ZK will just automatically do the same by default, the value
will be the each
object from the collection (here a string), the label will be computed via each.toString()
- the same string).
https://zkfiddle.org/sample/2msj324/5-Multiple-combobox-reduced
Asked: 2021-03-05 01:27:45 +0800
Seen: 10 times
Last updated: Mar 09
zkspringmvc jar licence is GPL ?
Build web application without any zul files
Custom component that extends Textbox does not fire onChange event
java.lang.NullPointerException to update to zk 8.0.1
"Spring Session" + ZK + "Spring core" @Listen method refresh the screen
zk8 client side binding to a viewmodel command seems not to work