-
Bug
-
Resolution: Fixed
-
Major
-
Freshly, 8.0.0, 8.0.1
-
None
-
None
-
ZK 8.0.1 S2
-
None
Example: http://zkfiddle.org/sample/1ai9bpt/4-children-binding-error
zul:
<zk> <window border="normal" title="hello" viewModel="@id('vm') @init('pkg$.TestViewModel')"> <div children="@load(vm.list)"> <template name="children" var="item"> <label value="@load(item)" /> </template> </div> <button label="add" onClick="@command('add')"/> <button label="remove" onClick="@command('remove')"/> </window> </zk>
ViewModel:
public class TestViewModel { ListModelList list = new ListModelList(); @Init public void init(){ list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); } @Command public void add(){ list.add(0, "A"); } @Command public void remove(){ list.remove(0); } public ListModelList getList(){ return list; } }
How to reproduce: Click remove, add, remove, add, remove, add...
Expected behavior: It should just remove "A", add it back, remove it again, ...
But it fails, the reason is a bug in: org.zkoss.bind.impl.BindChildRenderer
if (isListModel) { cbrCompsList = (List<Component[]>) owner.getAttribute(BinderCtrl.CHILDREN_BINDING_RENDERED_COMPONENTS); if (cbrCompsList == null) cbrCompsList = new LinkedList<Component[]>(); cbrCompsList.add(items); // <----- this here is not adding the components at the correct position