Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dst3.managedBeans;
- import java.util.List;
- import java.util.ResourceBundle;
- import javax.ejb.EJB;
- import javax.faces.application.FacesMessage;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.SessionScoped;
- import javax.faces.context.FacesContext;
- import dst3.dto.FlightInfo;
- import dst3.dto.ShoppingCartDto;
- import dst3.ejb.BookingManagerBean;
- import dst3.ejb.exception.LoginException;
- import dst3.ejb.exception.NotEnoughSeatsException;
- import dst3.ejb.exception.UnknownFlightException;
- @ManagedBean(name = "shoppingCartBean")
- @SessionScoped
- public class ShoppingCartBean {
- private final ResourceBundle rb = ResourceBundle.getBundle("messages");
- @EJB
- private BookingManagerBean bookingManagerBean;
- private FlightInfo currentFlight;
- private Double totalPrice = new Double(0);
- private List<ShoppingCartDto> shoppingCart;
- private boolean loggedin = false;
- private String username;
- private String password;
- public boolean isLoggedin() {
- return loggedin;
- }
- public void logout() {
- loggedin = false;
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("home:notification", new FacesMessage(rb
- .getString("logoutMessage")));
- }
- public boolean login() {
- boolean success = true;
- FacesContext ctx;
- try {
- bookingManagerBean.login(username, password);
- } catch (LoginException e) {
- ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("login:notification", new FacesMessage(rb
- .getString("loginError")));
- success = false;
- }
- if (success) {
- ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("home:notification", new FacesMessage(rb
- .getString("loginMessage")));
- }
- loggedin = true;
- return success;
- }
- public boolean addTickets() {
- boolean success = true;
- try {
- bookingManagerBean.addTickets(currentFlight.getId(), Integer
- .parseInt(currentFlight.getNrOfTickets()));
- } catch (NumberFormatException e) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(rb
- .getString("numberFormatException")));
- success = false;
- } catch (UnknownFlightException e) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(rb
- .getString("unknownFlightException")));
- success = false;
- } catch (NotEnoughSeatsException e) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(rb
- .getString("notEnoughSeatsException")));
- success = false;
- }
- // TODO msg entfernen.
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(
- currentFlight.getId() + " " + currentFlight.getNrOfTickets()));
- return success;
- }
- public boolean removeFlight() {
- boolean success = true;
- bookingManagerBean.removeTickets(currentFlight.getId());
- return success;
- }
- public boolean buyTickets() {
- boolean success = true;
- if (!loggedin) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(rb
- .getString("notLoggedIn")));
- success = false;
- } else {
- FacesContext ctx = FacesContext.getCurrentInstance();
- ctx.addMessage("shoppingCart:notification", new FacesMessage(rb
- .getString("ticketsBooked")));
- // TODO buchen
- }
- return success;
- }
- public void emptyShoopingCartOnLogout() {
- loggedin = false;
- }
- public List<ShoppingCartDto> getShoppingCart() {
- shoppingCart = bookingManagerBean.getShoppingCartData();
- return shoppingCart;
- }
- public Double getTotalPrice() {
- totalPrice = bookingManagerBean.getPrice().doubleValue();
- return totalPrice;
- }
- public void setTotalPrice(Double totalPrice) {
- this.totalPrice = totalPrice;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public FlightInfo getCurrentFlight() {
- return currentFlight;
- }
- public void setCurrentFlight(FlightInfo currentFlight) {
- this.currentFlight = currentFlight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement