From 8337dc841fd7953ed9a1500a66b490fc516a3efe Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 27 Mar 2008 16:32:04 +0000 Subject: [PATCH] polish --- .../booking/{ => jsf}/BookingController.java | 81 +++++++++++-------- .../booking/{ => jsf}/HotelController.java | 20 +++-- .../booking/{ => jsf}/SearchController.java | 63 ++++++++------- .../src/main/webapp/WEB-INF/faces-config.xml | 48 +++++------ 4 files changed, 119 insertions(+), 93 deletions(-) rename spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/{ => jsf}/BookingController.java (78%) rename spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/{ => jsf}/HotelController.java (73%) rename spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/{ => jsf}/SearchController.java (71%) diff --git a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/BookingController.java b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/BookingController.java similarity index 78% rename from spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/BookingController.java rename to spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/BookingController.java index 223c8aa0..dc8ce4a6 100644 --- a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/BookingController.java +++ b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/BookingController.java @@ -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; - } } diff --git a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/HotelController.java b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/HotelController.java similarity index 73% rename from spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/HotelController.java rename to spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/HotelController.java index 8d32150f..1be30b22 100644 --- a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/HotelController.java +++ b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/HotelController.java @@ -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; } + } diff --git a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/SearchController.java b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/SearchController.java similarity index 71% rename from spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/SearchController.java rename to spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/SearchController.java index b5981e95..4d516b55 100644 --- a/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/SearchController.java +++ b/spring-webflow-samples/jsf-booking/src/main/java/org/springframework/webflow/samples/booking/jsf/SearchController.java @@ -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"; + } + } diff --git a/spring-webflow-samples/jsf-booking/src/main/webapp/WEB-INF/faces-config.xml b/spring-webflow-samples/jsf-booking/src/main/webapp/WEB-INF/faces-config.xml index 4fb12bd8..ac3675d4 100644 --- a/spring-webflow-samples/jsf-booking/src/main/webapp/WEB-INF/faces-config.xml +++ b/spring-webflow-samples/jsf-booking/src/main/webapp/WEB-INF/faces-config.xml @@ -4,23 +4,31 @@ "http://java.sun.com/dtd/web-facesconfig_1_0.dtd"> + + + org.springframework.web.jsf.SpringBeanVariableResolver + com.sun.facelets.FaceletViewHandler + + bookingController - org.springframework.webflow.samples.booking.BookingController + org.springframework.webflow.samples.booking.jsf.BookingController request + searchController - org.springframework.webflow.samples.booking.SearchController + org.springframework.webflow.samples.booking.jsf.SearchController request bookingService #{bookingService} + hotelController - org.springframework.webflow.samples.booking.HotelController + org.springframework.webflow.samples.booking.jsf.HotelController request bookingService @@ -31,9 +39,10 @@ #{param.id} + bookingController - org.springframework.webflow.samples.booking.BookingController + org.springframework.webflow.samples.booking.jsf.BookingController request bookingService @@ -48,12 +57,21 @@ #{booking} + searchCriteria org.springframework.webflow.samples.booking.SearchCriteria request - + + + /main/enterSearchCriteria.xhtml + + reviewHotels + /main/reviewHotels.xhtml + + + /main/reviewHotels.xhtml @@ -66,24 +84,12 @@ - - - /main/enterSearchCriteria.xhtml - - reviewHotels - /main/reviewHotels.xhtml - - - - - - + /main/reviewHotel.xhtml book /booking/enterBookingDetails.xhtml - @@ -113,12 +119,8 @@ - - org.springframework.web.jsf.SpringBeanVariableResolver - com.sun.facelets.FaceletViewHandler - - org.springframework.faces.support.RequestLoggingPhaseListener + \ No newline at end of file