Advertisement
hsianghui

IS3106 Lab2 Exercise 5 (CustomerManagedBean.java)

Sep 16th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package managedbean;
  2.  
  3. import entity.Customer;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.List;
  7. import javax.annotation.PostConstruct;
  8. import javax.ejb.EJB;
  9. import javax.faces.bean.ManagedBean;
  10. import javax.faces.bean.RequestScoped;
  11. import javax.faces.event.ActionEvent;
  12. import session.CustomerSessionLocal;
  13.  
  14. @ManagedBean
  15. @RequestScoped
  16. public class CustomerManagedBean {
  17.  
  18.     @EJB
  19.     private CustomerSessionLocal customerSessionLocal;
  20.     private String name;
  21.     private byte gender;
  22.     private Date dob;
  23.     private List<Customer> customers;
  24.  
  25.     /**
  26.      * Creates a new instance of customerManagedBean
  27.      */
  28.     public CustomerManagedBean() {
  29.     }
  30.    
  31.     @PostConstruct
  32.     public void init(){
  33.         setCustomers(customerSessionLocal.searchCustomers(null));
  34.     }
  35.  
  36.     public void addCustomer(ActionEvent evt) {
  37.         Customer c = new Customer();
  38.         c.setName(name);
  39.         c.setGender(gender);
  40.         c.setDob(dob);
  41.         c.setCreated(new Date());
  42.         customerSessionLocal.createCustomer(c);
  43.     } //end addCustomer
  44.  
  45.     /**
  46.      * @return the name
  47.      */
  48.     public String getName() {
  49.         return name;
  50.     }
  51.  
  52.     /**
  53.      * @param name the name to set
  54.      */
  55.     public void setName(String name) {
  56.         this.name = name;
  57.     }
  58.  
  59.     /**
  60.      * @return the gender
  61.      */
  62.     public byte getGender() {
  63.         return gender;
  64.     }
  65.  
  66.     /**
  67.      * @param gender the gender to set
  68.      */
  69.     public void setGender(byte gender) {
  70.         this.gender = gender;
  71.     }
  72.  
  73.     /**
  74.      * @return the customers
  75.      */
  76.     public List<Customer> getCustomers() {
  77.         return customers;
  78.     }
  79.  
  80.     /**
  81.      * @param customers the customers to set
  82.      */
  83.     public void setCustomers(List<Customer> customers) {
  84.         this.customers = customers;
  85.     }
  86.  
  87.     /**
  88.      * @return the dob
  89.      */
  90.     public Date getDob() {
  91.         return dob;
  92.     }
  93.  
  94.     /**
  95.      * @param dob the dob to set
  96.      */
  97.     public void setDob(Date dob) {
  98.         this.dob = dob;
  99.     }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement