polish
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,23 +4,31 @@
|
||||
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
|
||||
|
||||
<faces-config>
|
||||
|
||||
<application>
|
||||
<variable-resolver>org.springframework.web.jsf.SpringBeanVariableResolver</variable-resolver>
|
||||
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
|
||||
</application>
|
||||
|
||||
<managed-bean>
|
||||
<managed-bean-name>bookingController</managed-bean-name>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.BookingController</managed-bean-class>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.jsf.BookingController</managed-bean-class>
|
||||
<managed-bean-scope>request</managed-bean-scope>
|
||||
</managed-bean>
|
||||
|
||||
<managed-bean>
|
||||
<managed-bean-name>searchController</managed-bean-name>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.SearchController</managed-bean-class>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.jsf.SearchController</managed-bean-class>
|
||||
<managed-bean-scope>request</managed-bean-scope>
|
||||
<managed-property>
|
||||
<property-name>bookingService</property-name>
|
||||
<value>#{bookingService}</value>
|
||||
</managed-property>
|
||||
</managed-bean>
|
||||
|
||||
<managed-bean>
|
||||
<managed-bean-name>hotelController</managed-bean-name>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.HotelController</managed-bean-class>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.jsf.HotelController</managed-bean-class>
|
||||
<managed-bean-scope>request</managed-bean-scope>
|
||||
<managed-property>
|
||||
<property-name>bookingService</property-name>
|
||||
@@ -31,9 +39,10 @@
|
||||
<value>#{param.id}</value>
|
||||
</managed-property>
|
||||
</managed-bean>
|
||||
|
||||
<managed-bean>
|
||||
<managed-bean-name>bookingController</managed-bean-name>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.BookingController</managed-bean-class>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.jsf.BookingController</managed-bean-class>
|
||||
<managed-bean-scope>request</managed-bean-scope>
|
||||
<managed-property>
|
||||
<property-name>bookingService</property-name>
|
||||
@@ -48,12 +57,21 @@
|
||||
<value>#{booking}</value>
|
||||
</managed-property>
|
||||
</managed-bean>
|
||||
|
||||
<managed-bean>
|
||||
<managed-bean-name>searchCriteria</managed-bean-name>
|
||||
<managed-bean-class>org.springframework.webflow.samples.booking.SearchCriteria</managed-bean-class>
|
||||
<managed-bean-scope>request</managed-bean-scope>
|
||||
</managed-bean>
|
||||
|
||||
|
||||
<navigation-rule>
|
||||
<from-view-id>/main/enterSearchCriteria.xhtml</from-view-id>
|
||||
<navigation-case>
|
||||
<from-outcome>reviewHotels</from-outcome>
|
||||
<to-view-id>/main/reviewHotels.xhtml</to-view-id>
|
||||
</navigation-case>
|
||||
</navigation-rule>
|
||||
|
||||
<navigation-rule>
|
||||
<from-view-id>/main/reviewHotels.xhtml</from-view-id>
|
||||
<navigation-case>
|
||||
@@ -66,24 +84,12 @@
|
||||
</navigation-case>
|
||||
</navigation-rule>
|
||||
|
||||
<navigation-rule>
|
||||
|
||||
<from-view-id>/main/enterSearchCriteria.xhtml</from-view-id>
|
||||
<navigation-case>
|
||||
<from-outcome>reviewHotels</from-outcome>
|
||||
<to-view-id>/main/reviewHotels.xhtml</to-view-id>
|
||||
</navigation-case>
|
||||
|
||||
</navigation-rule>
|
||||
|
||||
<navigation-rule>
|
||||
|
||||
<navigation-rule>
|
||||
<from-view-id>/main/reviewHotel.xhtml</from-view-id>
|
||||
<navigation-case>
|
||||
<from-outcome>book</from-outcome>
|
||||
<to-view-id>/booking/enterBookingDetails.xhtml</to-view-id>
|
||||
</navigation-case>
|
||||
|
||||
</navigation-rule>
|
||||
|
||||
<navigation-rule>
|
||||
@@ -113,12 +119,8 @@
|
||||
</navigation-case>
|
||||
</navigation-rule>
|
||||
|
||||
<application>
|
||||
<variable-resolver>org.springframework.web.jsf.SpringBeanVariableResolver</variable-resolver>
|
||||
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
|
||||
</application>
|
||||
|
||||
<lifecycle>
|
||||
<phase-listener>org.springframework.faces.support.RequestLoggingPhaseListener</phase-listener>
|
||||
</lifecycle>
|
||||
|
||||
</faces-config>
|
||||
Reference in New Issue
Block a user