From 7d8a3ce8ddfcf7128815311c7b3ca87efe48e79b Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 26 Feb 2014 22:01:25 -0500 Subject: [PATCH] Autowire BookingService into the HotelLazyDataModel --- .../samples/booking/HotelLazyDataModel.java | 13 +++++++++---- .../webflow/samples/booking/SearchCriteria.java | 9 --------- .../main/webapp/WEB-INF/flows/main/main-flow.xml | 14 ++++++++------ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/booking-faces/src/main/java/org/springframework/webflow/samples/booking/HotelLazyDataModel.java b/booking-faces/src/main/java/org/springframework/webflow/samples/booking/HotelLazyDataModel.java index 5d48baa..6093396 100644 --- a/booking-faces/src/main/java/org/springframework/webflow/samples/booking/HotelLazyDataModel.java +++ b/booking-faces/src/main/java/org/springframework/webflow/samples/booking/HotelLazyDataModel.java @@ -8,25 +8,30 @@ import java.util.Map; import org.primefaces.model.LazyDataModel; import org.primefaces.model.SortOrder; +import org.springframework.beans.factory.annotation.Autowired; public class HotelLazyDataModel extends LazyDataModel { private static final long serialVersionUID = -8832831134966938627L; - SearchCriteria searchCriteria; + private SearchCriteria searchCriteria; - BookingService bookingService; + private BookingService bookingService; private List hotels; private Hotel selected; - public HotelLazyDataModel(SearchCriteria searchCriteria, BookingService bookingService) { - this.searchCriteria = searchCriteria; + @Autowired + public void setBookingService(BookingService bookingService) { this.bookingService = bookingService; } + public void setSearchCriteria(SearchCriteria searchCriteria) { + this.searchCriteria = searchCriteria; + } + @Override public List load(int first, int pageSize, String sortField, SortOrder order, Map filters) { this.searchCriteria.setCurrentPage(first / pageSize + 1); diff --git a/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java b/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java index 9888777..8bf2cd7 100755 --- a/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java +++ b/booking-faces/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java @@ -2,8 +2,6 @@ package org.springframework.webflow.samples.booking; import java.io.Serializable; -import javax.faces.model.DataModel; - /** * A backing bean for the main hotel search form. Encapsulates the criteria needed to perform a hotel search. */ @@ -26,13 +24,6 @@ public class SearchCriteria implements Serializable { */ private int currentPage = 1; - /** - * Returns a {@link DataModel} based on the search criteria. - * @param bookingService the service to use to retrieve hotels. - */ - public DataModel getDataModel(BookingService bookingService) { - return new HotelLazyDataModel(this, bookingService); - } public String getSearchString() { return searchString; diff --git a/booking-faces/src/main/webapp/WEB-INF/flows/main/main-flow.xml b/booking-faces/src/main/webapp/WEB-INF/flows/main/main-flow.xml index 0ad4cc8..c08aa87 100755 --- a/booking-faces/src/main/webapp/WEB-INF/flows/main/main-flow.xml +++ b/booking-faces/src/main/webapp/WEB-INF/flows/main/main-flow.xml @@ -4,12 +4,13 @@ xsi:schemaLocation=" http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> - - + + - + @@ -18,9 +19,10 @@ - - - + + + +