You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2007/02/28 23:33:14 UTC

svn commit: r513062 - in /incubator/adffaces/trunk/trinidad/trinidad-api/src: main/java/org/apache/myfaces/trinidad/model/ test/java/org/apache/myfaces/trinidad/model/

Author: awiner
Date: Wed Feb 28 15:33:13 2007
New Revision: 513062

URL: http://svn.apache.org/viewvc?view=rev&rev=513062
Log:
ADFFACES-382: SortableModel.getRowKey() returns sortedIndex
- Row keys in SortableModel were not stable after sorting - so, for instance,
  the selection would jump to a totally different row after sorting
- Checked in patch from John Fan

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java
    incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetImplTest.java
    incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetTreeImplTest.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java?view=diff&rev=513062&r1=513061&r2=513062
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/SortableModel.java Wed Feb 28 15:33:13 2007
@@ -119,7 +119,7 @@
   public Object getRowKey()
   {
     return isRowAvailable()
-      ? String.valueOf(getRowIndex())
+      ? _model.getRowIndex()
       : null;
   }
 
@@ -130,7 +130,7 @@
   @Override
   public void setRowKey(Object key)
   {
-    setRowIndex(_toRowIndex((String) key));
+    _model.setRowIndex(_toRowIndex(key));
   }
 
   /**
@@ -271,7 +271,7 @@
       for(int i=0; i<_baseIndicesList.size(); i++)
       {
         Integer base = _baseIndicesList.get(i);
-        _sortedIndicesList.set(base.intValue(), new Integer(i));
+        _sortedIndicesList.set(base.intValue(), i);
       }
     }
 
@@ -295,18 +295,18 @@
     return index;
   }
 
-  private int _toRowIndex(String rowKey)
+  private int _toRowIndex(Object rowKey)
   {
     if (rowKey == null)
       return -1;
 
     try
     {
-      return Integer.parseInt(rowKey);
+      return ((Integer)rowKey).intValue();
     }
-    catch (NumberFormatException nfe)
+    catch (ClassCastException e)
     {
-      _LOG.warning("Illegal rowKey:" + rowKey, nfe);
+      _LOG.warning("Invalid rowkey:" + rowKey + " type:" + rowKey.getClass(), e);
       return -1;
     }
   }
@@ -324,7 +324,7 @@
     {
       for(int i=0; i<desiredSize; i++)
       {
-        add(new Integer(i));
+        add(i);
       }
     }
   }

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetImplTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetImplTest.java?view=diff&rev=513062&r1=513061&r2=513062
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetImplTest.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetImplTest.java Wed Feb 28 15:33:13 2007
@@ -42,6 +42,10 @@
 
 /**
  * Test for the RowKeySetImpl class.
+ * 
+ * There is a hardcoded dependency between this test and the SortableModel implementation that 
+ * happens to be used by ModelUtils.toCollectionModel().
+ * 
  * @author Arjuna Wijeyekoon
  */
 public final class RowKeySetImplTest extends AbstractJsfTestCase
@@ -315,7 +319,7 @@
 
       bytes = bos.toByteArray();
       // test to make sure that the serialized size is reasonable:
-     assertTrue(bytes.length <= 100);
+     assertTrue(bytes.length <= 200);
      assertTrue(bytes.length >= 80);
     }
 
@@ -389,7 +393,7 @@
 
     for(int i=0; i<sz; i++)
     {
-      String rowKey = (String) selectedList.get(i);
+      Object rowKey = selectedList.get(i);
       table.setRowKey(rowKey);
       Entry val = (Entry) table.getRowData();
 
@@ -468,9 +472,9 @@
     }
   }
 
-  private static String _getKey(int index)
+  private static Object _getKey(int index)
   {
-    return String.valueOf(index);
+    return index;
   }
 
 //  private static int _getIndex(String key)

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetTreeImplTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetTreeImplTest.java?view=diff&rev=513062&r1=513061&r2=513062
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetTreeImplTest.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/model/RowKeySetTreeImplTest.java Wed Feb 28 15:33:13 2007
@@ -37,7 +37,10 @@
 import org.apache.myfaces.trinidad.model.TreeModel;
 import org.apache.shale.test.base.AbstractJsfTestCase;
 
-
+/**
+ * There is a hardcoded dependency between this test and the SortableModel implementation that 
+ * happens to be used by ModelUtils.toCollectionModel().
+ */
 public class RowKeySetTreeImplTest extends AbstractJsfTestCase
 {
   public RowKeySetTreeImplTest(String name)
@@ -280,7 +283,7 @@
     // we're doing a test here to warn the developer if the
     // serialized size changes significantly. If the size changes are
     // expected, then change the expected range for these tests:
-    assertTrue(bytes.length < 650);
+    assertTrue(bytes.length < 1000);
     assertTrue(bytes.length > 615);
 
     ObjectInputStream in =
@@ -345,8 +348,8 @@
     private final TreeModel _model;
   }
 
-  private static final List<Object> _0 = _createPath("0");
-  private static final List<Object> _011 = _createPath("0", "1", "1");
-  private static final List<Object> _2 = _createPath("2");
-  private static final List<Object> _20 = _createPath("2", "0");
+  private static final List<Object> _0 = _createPath(0);
+  private static final List<Object> _011 = _createPath(0, 1, 1);
+  private static final List<Object> _2 = _createPath(2);
+  private static final List<Object> _20 = _createPath(2, 0);
 }