Java Reference
In-Depth Information
Adding a controller to drive user requests
The link between the persistence layer and the user's view falls on the
TheatreSetupService
bean, which will drive requests to the actual services exposed
by our application. Since this bean will be bound to
RequestScope
and we need to ex-
pose it to our views as well (using
@Named
), we can use the convenient
@Model
annota-
tion for it, which is a sum of the following two attributes:
@Model
public class TheatreSetupService {
@Inject
private FacesContext facesContext;
@Inject
private TicketService ticketService;
@Inject
private List<SeatType> seatTypes;
@Produces [1]
@Named
private SeatType newSeatType;
@PostConstruct
public void initNewSeatType() {
newSeatType = new SeatType();
}
public String createTheatre() {
ticketService.createTheatre(seatTypes);
return "book";
}
public String restart() {
ticketService.doCleanUp();
return "/index"; [4]
}