Java Reference
In-Depth Information
}
public void bookSeat(int seatId) {
logger.info("Booking seat " + seatId);
int seatPrice = theatreBox.getSeatPrice(seatId);
if (seatPrice > money) {
FacesMessage m = new
FacesMessage(FacesMessage.SEVERITY_ERROR, "Not enough
Money!", "Registration unsuccessful"); [6]
facesContext.addMessage(null, m);
return;
}
theatreBox.buyTicket(seatId);
FacesMessage m = new
FacesMessage(FacesMessage.SEVERITY_INFO, "Booked!",
"Booking successful");
facesContext.addMessage(null, m);
logger.info("Seat booked.");
money = money - seatPrice;
}
public int getMoney() {
return money;
}
}
As you can see, the bean has been tagged as Named [1] , which means that it can be dir-
ectly referenced in our JSF pages. The bean is SessionScoped [2] since it stores the
amount of money available to the customer during its session.
We would also like to inject logger [3] and FacesContextFacexContexts
[5] instead of manually defining it. To do this, we will need to register a bean that pro-
duces loggers, which are parameterized with the name of the class. We will cover this pro-
cess of producing beans in a moment.
Search WWH ::




Custom Search