Package eja.controllers

Source Code of eja.controllers.CustomerController

package eja.controllers;

import eja.ejb.dao.CustomerDao;
import eja.ejb.entities.Customer;
import java.util.Collection;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
*
* @author fero
*/
@ManagedBean
@RequestScoped
public class CustomerController {

    @EJB
    private CustomerDao _customerDao;

    @ManagedProperty("#{param['id']}")
    private int id;
    private String name;
    private String email;
    private String phone;
    private String comRegNo;
    private String vatNo;



    private Customer _customer;

    /** Creates a new instance of Customer */
    public CustomerController() {
    }

    public Collection<Customer> getAllCustomers() {
        return this._customerDao.getAllCustomers();
    }

    public String edit() {
        this._customer = (this.id != 0) ? this._customerDao.getCustomerById(this.id) : new Customer();
        this._customer.setName(this.name);
        this._customer.setEmail(this.email);
        this._customer.setPhone(this.phone);
        this._customer.setComRegNo(this.comRegNo);
        this._customer.setVatNo(this.vatNo);

        this._customerDao.saveCustomer(this._customer);
        return "customer-details";
    }

    public Customer getCustomer() {
        return this._customer;
    }

    public void load() {
        this._customer = this._customerDao.getCustomerById(this.id);
        this.name = this._customer.getName();
        this.email = this._customer.getEmail();
        this.phone = this._customer.getPhone();
        this.comRegNo = this._customer.getComRegNo();
        this.vatNo = this._customer.getVatNo();
    }


    // Getters & Setters
    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        if (id == 0)
            return;
       
        this.id = id;
        this.load();
    }

    public String getComRegNo() {
        return comRegNo;
    }

    public void setComRegNo(String comRegNo) {
        this.comRegNo = comRegNo;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getVatNo() {
        return vatNo;
    }

    public void setVatNo(String vatNo) {
        this.vatNo = vatNo;
    }
}
TOP

Related Classes of eja.controllers.CustomerController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.