Thanks for your response.
I'm well aware that all objects inside viewScope and flowScope should be serializable. However i'm not achieving proper datatable pagination without executing on the fly the proper query to obtain my page. And in regarding to DataModel of JSF, the objective of that object is to be used as a facade to your data (not to be build on every request of a paginated table, for example). Offcourse i can load all objects into DataModel object, but with huge datasets this will cause memory problems.
Let me give you a proper example from booking faces sample app. In Booking-Faces (that comes with SpringWebflow distribution) sample app you have the following flow service support class HotelLazyDataModel:
Code:
public class HotelLazyDataModel extends LazyDataModel<Hotel> {
private static final long serialVersionUID = -8832831134966938627L;
SearchCriteria searchCriteria;
BookingService bookingService;
private Hotel selected;
public HotelLazyDataModel(SearchCriteria searchCriteria, BookingService bookingService) {
this.searchCriteria = searchCriteria;
this.bookingService = bookingService;
}
@Override
public List<Hotel> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
searchCriteria.setCurrentPage(first / pageSize + 1);
return bookingService.findHotels(searchCriteria, first, sortField, sortOrder.equals(SortOrder.ASCENDING));
}
(...)
}
You can see that the pagination is properly handled by BookingService. If you then go to BookingService impl:
Code:
@Service("bookingService")
@Repository
public class JpaBookingService implements BookingService, Serializable {
private static final long serialVersionUID = 1L;
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager em) {
this.em = em;
}
(...)
}
You can see that they use directly the EntityManager! Since i'm using SpringData i want obviously to reuse the JpaRepositories in my service. I'm not that happy to have to rewrite queries to obtain the objects again directly using EntityManager!
Maybe i'm doing this wrong, but i still cannot figure out the best way to integrate Spring Data with SpringWebflow and JSF Model objects.
Best Regards