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.util.resource.Labels; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.ListModelList; import com.contact.app.constraint.CustomConstraint; import com.contact.app.entity.Address; import com.contact.app.entity.Contact; import com.contact.app.entity.Salutation; import com.contact.app.service.ContactService; import com.contact.app.validator.CustomEmailValidator; 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); } @Command @NotifyChange({"contact","model"}) public void saveContact(){ System.out.println("contact detail ------>"+contact.getFirstname()); //contactService.addContact(contact); } @Command @NotifyChange({"contact","model","deleteMessage"}) public void deleteContact(){ //contactService.removeContact(contact.getId());//delete selected // getModel().remove(contact); contact = null; //clean the selected deleteMessage = null; } @Command @NotifyChange("deleteMessage") public void confirmDelete(){ //set the message to show to user String msg = Labels.getLabel("contact.confirm.delete", new String[] {contact.getFirstname()}); deleteMessage = msg+" ?"; } @Command @NotifyChange("deleteMessage") public void cancelDelete(){ //clear the message deleteMessage = null; } //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; } }