package eja.controllers;
import eja.ejb.dao.CategoryDao;
import eja.ejb.dao.HotelDao;
import eja.ejb.entities.Category;
import eja.ejb.entities.Hotel;
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 HotelController {
@EJB
private HotelDao _hotelDao;
@EJB
private CategoryDao _categoryDao;
@ManagedProperty("#{param['id']}")
private int id;
private String name;
private String email;
private String phone;
private String comRegNo;
private String vatNo;
private Hotel _hotel;
private Collection<Category> _categories;
/** Creates a new instance of Hotel */
public HotelController() {
}
public Hotel getHotelById(){
return this._hotelDao.getHotelById(id);
}
public Collection<Hotel> getAllHotels() {
return this._hotelDao.getAllHotels();
}
public Collection<Category> getAllCategories() {
return this._categoryDao.getAllCategories();
}
public String edit() {
this._hotel = (this.id != 0) ? this._hotelDao.getHotelById(this.id) : new Hotel();
this._hotel.setName(this.name);
this._hotel.setEmail(this.email);
this._hotel.setPhone(this.phone);
this._hotel.setComRegNo(this.comRegNo);
this._hotel.setVatNo(this.vatNo);
this._hotel.setCategories(this._categories);
this._hotelDao.saveHotel(this._hotel);
return "hotel-details";
}
public Hotel getHotel() {
return this._hotel;
}
public void load() {
this._hotel = this._hotelDao.getHotelById(this.id);
this.name = this._hotel.getName();
this.email = this._hotel.getEmail();
this.phone = this._hotel.getPhone();
this.comRegNo = this._hotel.getComRegNo();
this.vatNo = this._hotel.getVatNo();
this._categories = this._hotel.getCategories();
}
// 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;
}
public Collection<Category> getCategories() {
return _categories;
}
public void setCategories(Collection<Category> _categories) {
this._categories = _categories;
}
}