package com.ebpm.webdemo.zk;

import java.util.Collection;
import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.ListModelArray;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Window;
import com.ebpm.webdemo.common.PersonBean;
import com.ebpm.webdemo.common.PersonDAO;

/**
 * SimpleWindow3b.java
 
 * demonstrate "codeless databinding"
 * binding is defined in zul-file only 
 */
public class SimpleWindow3b extends Window {
    
    public PersonBean personBean = new PersonBean();
    private ListModelList listModel;

    public PersonBean getPersonBean() {
      return personBean;
    }

    public Collection getAllPersons() {
      return  PersonDAO.getInstance().getAllPersons();
    }

    public void onCreate() {
      // get the model via Window / Listbox / Model
      listModel = (ListModelList) ((Listboxthis.getFellow("personsList")).getModel();
    }
    /*
     * Process Submitbutton and enter-key
     */
    public void onOK() {
      
      PersonDAO.getInstance().addPerson(personBean);  // add the person (from inputfields) to model
      listModel.add(personBean);                      // add only the new person to UI   
      this.personBean = new PersonBean()// prepare the next input
    }
    /*
     * process Cancelbutton and esc-key
     */
    public void onCancel() {
      Executions.sendRedirect("/index.jsp");
    }
}