Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by PeterMaloney:
http://wiki.apache.org/tapestry/Tapestry5HibernateGridDatasource3

------------------------------------------------------------------------------
  
  
  {{{#!java
+ package com.sajus.tapestry.console3.util;
+ 
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
@@ -51, +53 @@

      private static Category log = Category.getInstance( 
HibernateGridDataSource.class );
  
      private int rowCount = -1;
-     private Iterator<?> pageRowList;
+     private List<?> pageRowList;
  
      private Class<?> rowType;
  
@@ -178, +180 @@

          q.setFirstResult(startIndex);
          q.setFetchSize(maxResults);
          q.setMaxResults(maxResults);
-         Collection<?> rows = q.list();
+         List<?> rows = q.list();
-         pageRowList = rows.iterator();
+         pageRowList = rows;  
+         
      }
  
      /**
@@ -189, +192 @@

       */
      public Object getRowValue(int index) {
          Object entityObject = null;
- 
+         
-         if (pageRowList.hasNext())
+         if (pageRowList.size() > index)
-             entityObject = pageRowList.next();
+             entityObject = pageRowList.get(index);
- 
+         else {
+             // This else is a work around for getRowValue(...) with incorrect 
index.
+             // The theory is that the grid is caching the number of rows so 
if the row count
+             // on the previous request was larger, then index can be out of 
bounds.
+             try {
+                 return getRowType().newInstance(); 
+             } catch (Exception e) {
+                 throw new RuntimeException("index was invalid, and failed to 
create a dummy row.", e);
+             } 
+         }
          return entityObject;
      }
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to