Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3026

ChildrenBinding breaks when adding an element not to the end of the ListModelList

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 8.0.1
    • Freshly, 8.0.0, 8.0.1
    • None
    • None
    • ZK 8.0.1 S2

      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
      		
      

            DevChu DevChu
            aznavour aznavour
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 40 minutes
                40m