package com.contact.app.viewmodel; import java.util.ArrayList; import java.util.List; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.Component; import com.contact.app.entity.Address; import com.contact.app.entity.Contact; public class ContactVM { //create the entity Contact contact; List model; List
address; List
otherAddress; String deleteMessage; //action commands @Command @NotifyChange({"contact","model"}) public void newContact(){ Contact mycontact = new Contact(); //getModel().add(mycontact); contact = mycontact; } @Command @NotifyChange("address") public void addMoreAddress(){ if(address != null && address.size()>0){ address.add(new Address()); }else{ address = new ArrayList
(); address.add(new Address()); } } @Command @NotifyChange("address") public void removeAddress(@BindingParam("index") int index, @BindingParam("comp") Component comp){ address.remove(index); } @Command @NotifyChange("otherAddress") public void addMoreOtherAddress(){ if(otherAddress != null && otherAddress.size()>0){ otherAddress.add(new Address()); }else{ otherAddress = new ArrayList
(); otherAddress.add(new Address()); } } @Command @NotifyChange("otherAddress") public void removeOtherAddress(@BindingParam("index") int index, @BindingParam("comp") Component comp){ otherAddress.remove(index); } //setter and getters public String getDeleteMessage() { return deleteMessage; } @NotifyChange("contact") public void setContact(Contact contact) { this.contact = contact; } public Contact getContact() { return contact; } public List
getAddress() { return address; } public void setAddress(List
address) { this.address = address; } public List
getOtherAddress() { return otherAddress; } public void setOtherAddress(List
otherAddress) { this.otherAddress = otherAddress; } }