Author: norman.richards(a)jboss.com
Date: 2008-04-14 13:17:50 -0400 (Mon, 14 Apr 2008)
New Revision: 7943
Modified:
branches/Seam_2_0/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
Log:
JBSEAM-2821
Modified:
branches/Seam_2_0/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
===================================================================
---
branches/Seam_2_0/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java 2008-04-14
16:38:30 UTC (rev 7942)
+++
branches/Seam_2_0/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java 2008-04-14
17:17:50 UTC (rev 7943)
@@ -28,6 +28,7 @@
private String searchString;
private int pageSize = 10;
private int page;
+ private boolean nextPageAvailable = false;
@DataModel
private List<Hotel> hotels;
@@ -45,15 +46,23 @@
private void queryHotels()
{
- hotels = em.createQuery("select h from Hotel h where lower(h.name) like
#{pattern} or lower(h.city) like #{pattern} or lower(h.zip) like #{pattern} or
lower(h.address) like #{pattern}")
- .setMaxResults(pageSize)
- .setFirstResult( page * pageSize )
- .getResultList();
+ List<Hotel> results = em.createQuery("select h from Hotel h where
lower(h.name) like #{pattern} or lower(h.city) like #{pattern} or lower(h.zip) like
#{pattern} or lower(h.address) like #{pattern}")
+ .setMaxResults(pageSize+1)
+ .setFirstResult( page * pageSize )
+ .getResultList();
+
+
+ nextPageAvailable = results.size() > pageSize;
+ if (nextPageAvailable) {
+ hotels = results.subList(0,pageSize);
+ } else {
+ hotels = results;
+ }
}
public boolean isNextPageAvailable()
{
- return hotels!=null && hotels.size()==pageSize;
+ return nextPageAvailable;
}
public int getPageSize() {
@@ -83,4 +92,4 @@
@Remove
public void destroy() {}
-}
\ No newline at end of file
+}