This commit is contained in:
Keith Donald
2008-03-27 16:32:04 +00:00
parent 18b0fde44a
commit 8337dc841f
4 changed files with 119 additions and 93 deletions

View File

@@ -1,13 +1,15 @@
package org.springframework.webflow.samples.booking;
package org.springframework.webflow.samples.booking.jsf;
import java.util.Calendar;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class BookingController {
import org.springframework.webflow.samples.booking.Booking;
import org.springframework.webflow.samples.booking.BookingService;
import org.springframework.webflow.samples.booking.Hotel;
private static final String REVIEW_BOOKING_OUTCOME = "reviewBooking";
public class BookingController {
private BookingService bookingService;
@@ -15,10 +17,43 @@ public class BookingController {
private Hotel hotel = new Hotel();
private Booking booking = new Booking(hotel, new User());
private Booking booking;
private boolean initialized = false;
public void setBookingService(BookingService bookingService) {
this.bookingService = bookingService;
}
public Long getHotelId() {
return hotelId;
}
public void setHotelId(Long hotelId) {
if (hotelId != null && hotelId != 0 && !initialized) {
booking = bookingService.createBooking(hotelId, getCurrentUser());
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("booking", booking);
initialized = true;
}
this.hotelId = hotelId;
}
public Booking getBooking() {
return booking;
}
public void setBooking(Booking booking) {
this.booking = booking;
}
public Hotel getHotel() {
return hotel;
}
public void setHotel(Hotel hotel) {
this.hotel = hotel;
}
public String processBooking() {
FacesContext context = FacesContext.getCurrentInstance();
Calendar calendar = Calendar.getInstance();
@@ -35,7 +70,7 @@ public class BookingController {
valid = false;
}
if (valid) {
return REVIEW_BOOKING_OUTCOME;
return "reviewBooking";
} else {
return null;
}
@@ -43,45 +78,21 @@ public class BookingController {
public String confirm() {
bookingService.saveBooking(booking);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("booking");
removeBookingFromSession();
return "confirm";
}
public String cancel() {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("booking");
removeBookingFromSession();
return "cancel";
}
public Long getHotelId() {
return hotelId;
private String getCurrentUser() {
return "jeremy";
}
public void setHotelId(Long hotelId) {
if (hotelId != null && hotelId != 0 && !initialized) {
booking = bookingService.createBooking(hotelId, "jeremy");
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("booking", booking);
initialized = true;
}
this.hotelId = hotelId;
private void removeBookingFromSession() {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("booking");
}
public Hotel getHotel() {
return hotel;
}
public void setHotel(Hotel hotel) {
this.hotel = hotel;
}
public Booking getBooking() {
return booking;
}
public void setBooking(Booking booking) {
this.booking = booking;
}
public void setBookingService(BookingService bookingService) {
this.bookingService = bookingService;
}
}

View File

@@ -1,4 +1,7 @@
package org.springframework.webflow.samples.booking;
package org.springframework.webflow.samples.booking.jsf;
import org.springframework.webflow.samples.booking.BookingService;
import org.springframework.webflow.samples.booking.Hotel;
public class HotelController {
@@ -8,13 +11,6 @@ public class HotelController {
private Hotel hotel;
public Hotel getHotel() {
if (hotel == null && hotelId != null) {
hotel = bookingService.findHotelById(hotelId);
}
return hotel;
}
public void setBookingService(BookingService bookingService) {
this.bookingService = bookingService;
}
@@ -23,7 +19,15 @@ public class HotelController {
this.hotelId = hotelId;
}
public Hotel getHotel() {
if (hotel == null && hotelId != null) {
hotel = bookingService.findHotelById(hotelId);
}
return hotel;
}
public Long getHotelId() {
return hotelId;
}
}

View File

@@ -1,4 +1,4 @@
package org.springframework.webflow.samples.booking;
package org.springframework.webflow.samples.booking.jsf;
import java.util.List;
@@ -6,15 +6,39 @@ import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.springframework.webflow.samples.booking.Booking;
import org.springframework.webflow.samples.booking.BookingService;
import org.springframework.webflow.samples.booking.SearchCriteria;
public class SearchController {
private BookingService bookingService;
private SearchCriteria searchCriteria = new SearchCriteria();
private DataModel hotels = null;
private DataModel hotels;
private DataModel bookings = null;
private DataModel bookings;
public void setBookingService(BookingService bookingService) {
this.bookingService = bookingService;
}
public SearchCriteria getSearchCriteria() {
return searchCriteria;
}
public DataModel getHotels() {
return hotels;
}
public DataModel getBookings() {
if (bookings == null) {
// load the current user's bookings from the database
bookings = new ListDataModel(bookingService.findBookings(getCurrentUser()));
}
return bookings;
}
public String search() {
searchCriteria.resetPage();
@@ -32,34 +56,19 @@ public class SearchController {
executeSearch();
}
private void executeSearch() {
hotels = new ListDataModel();
hotels.setWrappedData(bookingService.findHotels(searchCriteria));
}
public SearchCriteria getSearchCriteria() {
return searchCriteria;
}
public void setBookingService(BookingService bookingService) {
this.bookingService = bookingService;
}
public DataModel getHotels() {
return hotels;
}
public DataModel getBookings() {
if (bookings == null) {
bookings = new ListDataModel(bookingService.findBookings("jeremy"));
}
return bookings;
}
public void cancelBookingListener(ActionEvent event) {
Booking booking = (Booking) bookings.getRowData();
bookingService.cancelBooking(booking);
((List) bookings.getWrappedData()).remove(booking);
}
private void executeSearch() {
hotels = new ListDataModel();
hotels.setWrappedData(bookingService.findHotels(searchCriteria));
}
private String getCurrentUser() {
return "jeremy";
}
}