Autowire BookingService into the HotelLazyDataModel

This commit is contained in:
Rossen Stoyanchev
2014-02-26 22:01:25 -05:00
parent addc213422
commit 7d8a3ce8dd
3 changed files with 17 additions and 19 deletions

View File

@@ -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<Hotel> {
private static final long serialVersionUID = -8832831134966938627L;
SearchCriteria searchCriteria;
private SearchCriteria searchCriteria;
BookingService bookingService;
private BookingService bookingService;
private List<Hotel> 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<Hotel> load(int first, int pageSize, String sortField, SortOrder order, Map<String, String> filters) {
this.searchCriteria.setCurrentPage(first / pageSize + 1);

View File

@@ -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<Hotel> getDataModel(BookingService bookingService) {
return new HotelLazyDataModel(this, bookingService);
}
public String getSearchString() {
return searchString;

View File

@@ -4,12 +4,13 @@
xsi:schemaLocation="
http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.SearchCriteria" />
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.SearchCriteria"/>
<view-state id="enterSearchCriteria">
<on-render>
<evaluate expression="bookingService.findBookings(currentUser?.name)" result="viewScope.bookings" result-type="dataModel" />
<evaluate expression="bookingService.findBookings(currentUser?.name)"
result="viewScope.bookings" result-type="dataModel" />
</on-render>
<transition on="search" to="reviewHotels"/>
<transition on="cancelBooking">
@@ -18,9 +19,10 @@
</view-state>
<view-state id="reviewHotels">
<on-entry>
<set name="viewScope.hotels" value="searchCriteria.getDataModel(bookingService)" />
</on-entry>
<var name="hotels" class="org.springframework.webflow.samples.booking.HotelLazyDataModel"/>
<on-render>
<evaluate expression="hotels.setSearchCriteria(searchCriteria)" />
</on-render>
<transition on="select" to="reviewHotel">
<set name="flowScope.hotel" value="hotels.selected" />
</transition>