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

The expression reference doesn't update while change the instant of the reference

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.0.1
    • Freshly
    • Databind 2
    • None

      TestDataModel.java
      package bean;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import org.zkoss.bind.annotation.Command;
      import org.zkoss.bind.annotation.NotifyChange;
      import org.zkoss.zul.ListModel;
      import org.zkoss.zul.ListModelList;
      
      public class TestDataModel {
      
      	private Person jimmy;
      	private Person katrina;
      	private Person selectedPerson;
      	private Person newPerson;
      	private List<Person> persons;
      	
      	
      	public TestDataModel() {
      		selectedPerson=	jimmy = new Person("Jimmy", "Shiau", 27, false);
      		katrina = new Person("Katrina", "Lin", 24, true);
      		newPerson = new Person("new", "new", 1, false);
      
      		persons = new ArrayList<Person>();
      		persons.add(jimmy);
      		persons.add(katrina);
      	}
      
      	public Person getJimmy() {
      		return jimmy;
      	}
      
      	public Person getKatrina() {
      		return katrina;
      	}
      
      
      	public List<Person> getPersons() {
      		return persons;
      	}
      
      	public ListModel<Person> getPersonsModel() {
      		
      		return new ListModelList<Person>(persons);
      	}
      
      	public Person getSelectedPerson() {
      		return selectedPerson;
      	}
      
      	@NotifyChange
      	public void setSelectedPerson(Person selectedPerson) {
      		this.selectedPerson = selectedPerson;
      	}
      
      	@Command
      	@NotifyChange("persons")
      	public void add() {
      		persons.add(newPerson.clone());
      	}
      
      	@Command
      	@NotifyChange("persons")
      	public void update() {
      	}
      
      
      	public Person getNewPerson() {
      		return newPerson;
      	}
      
      	@NotifyChange
      	public void setNewPerson(Person newPerson) {
      		this.newPerson = newPerson;
      	}
      
      
      	
      	public static class Person implements Cloneable {
      		private String _firstName = "";
      		private String _lastName = "";
      		private Boolean _married = true;
      		private int age;
      
      		public Person(String firstName, String lastName, int age, Boolean married) {
      			super();
      			this._firstName = firstName;
      			this._lastName = lastName;
      			this._married = married;
      			this.age = age;
      		}
      
      		public Person clone() {
      			try {
      				return (Person) super.clone();
      			} catch (CloneNotSupportedException e) {
      				return null;
      			}
      		}
      
      		public String getFirstName() {
      			return _firstName;
      		}
      
      		public void setFirstName(String firstName) {
      			this._firstName = firstName;
      		}
      
      		public String getLastName() {
      			return _lastName;
      		}
      
      		public void setLastName(String lastName) {
      			this._lastName = lastName;
      		}
      
      		public Boolean getMarried() {
      			return _married;
      		}
      
      		public void setMarried(Boolean married) {
      			this._married = married;
      		}
      
      		public String getFullName() {
      			return _firstName + " " + _lastName;
      		}
      
      		public int getAge() {
      			return age;
      		}
      
      		public void setAge(int age) {
      			this.age = age;
      		}
      
      	}
      }
      
      
      test.zul
      <zk>
      	<window apply="org.zkoss.bind.BindComposer"  
      		viewModel="@id('vm')@init('bean.TestDataModel')" >
      		
      		<listbox width="500px" model="@load(vm.persons)" 
      			selectedItem="@bind(vm.selectedPerson)" checkmark="true">
      			<listhead>
      				<listheader label="col" width="200px"/>
      				<listheader label="col"/>
      				<listheader label="col"/>
      				<listheader label="col"/>
      			</listhead>
      		    <template name="model" var="p">
      		        <listitem>
      		        	<listcell>
      		        		<textbox value="@bind(p.firstName)"/>
      		        	</listcell>
      		        	<listcell label="@load(p.lastName)"/>
      		        	<listcell label="@load(p.married)"/>
      		        	<listcell label="@load(p.age)"/>
      		        </listitem>
      		    </template>
      		</listbox>
      		<label value="@load(vm.selectedPerson.fullName)"/>
      		<label value="@load(vm.selectedPerson.firstName)"/>
      		<label value="@load(vm.selectedPerson.married)"/>
      		<div p="@ref(vm.selectedPerson)">
      		    <label value="@load(p.firstName)" />
      		    <label value="@load(p.lastName)" />
      		</div>
      	</window>
      </zk>
      

            Unassigned Unassigned
            jimmyshiau jimmyshiau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: