[seam-commits] Seam SVN: r7944 - trunk/examples/booking/src/org/jboss/seam/example/booking.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 14 13:33:28 EDT 2008


Author: norman.richards at jboss.com
Date: 2008-04-14 13:33:28 -0400 (Mon, 14 Apr 2008)
New Revision: 7944

Modified:
   trunk/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
Log:
JBSEAM-2821

Modified: trunk/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
===================================================================
--- trunk/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java	2008-04-14 17:17:50 UTC (rev 7943)
+++ trunk/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java	2008-04-14 17:33:28 UTC (rev 7944)
@@ -21,41 +21,48 @@
 @Restrict("#{identity.loggedIn}")
 public class HotelSearchingAction implements HotelSearching
 {
+    @PersistenceContext
+    private EntityManager em;
+    
+    private String searchString;
+    private int pageSize = 10;
+    private int page;
+    private boolean nextPageAvailable;
    
-   @PersistenceContext
-   private EntityManager em;
+    @DataModel
+    private List<Hotel> hotels;
    
-   private String searchString;
-   private int pageSize = 10;
-   private int page;
+    public void find() 
+    {
+        page = 0;
+        queryHotels();
+    }
+
+    public void nextPage() 
+    {
+        page++;
+        queryHotels();
+    }
+    
+    private void queryHotels() {
+        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 nextPageAvailable;
+    }
    
-   @DataModel
-   private List<Hotel> hotels;
-   
-   public void find()
-   {
-      page = 0;
-      queryHotels();
-   }
-   public void nextPage()
-   {
-      page++;
-      queryHotels();
-   }
-      
-   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();
-   }
-   
-   public boolean isNextPageAvailable()
-   {
-      return hotels!=null && hotels.size()==pageSize;
-   }
-   
    public int getPageSize() {
       return pageSize;
    }
@@ -83,4 +90,4 @@
    
    @Remove
    public void destroy() {}
-}
\ No newline at end of file
+}




More information about the seam-commits mailing list