You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/08/08 20:38:38 UTC

svn commit: r1155049 - in /myfaces/core/trunk/api/src/main/java/javax/faces/model: DataModel.java ResultSetDataModel.java

Author: lu4242
Date: Mon Aug  8 18:38:37 2011
New Revision: 1155049

URL: http://svn.apache.org/viewvc?rev=1155049&view=rev
Log:
MYFACES-3270 DataModel.iterator cannot assume getRowCount will be always set

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/model/DataModel.java
    myfaces/core/trunk/api/src/main/java/javax/faces/model/ResultSetDataModel.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/model/DataModel.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/model/DataModel.java?rev=1155049&r1=1155048&r2=1155049&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/model/DataModel.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/model/DataModel.java Mon Aug  8 18:38:37 2011
@@ -174,9 +174,15 @@ public abstract class DataModel<E> imple
     {
         private int nextRowIndex = 0;
         
+        public DataModelIterator()
+        {
+            setRowIndex(nextRowIndex);
+        }
+        
         public boolean hasNext()
         {
-            return nextRowIndex < getRowCount();
+            //row count could be unknown, like in ResultSetDataModel
+            return isRowAvailable();
         }
 
         public E next()
@@ -185,18 +191,12 @@ public abstract class DataModel<E> imple
             //       Or the spec needs to specify that the iterator alters the selected row explicitely
             if (hasNext())
             {
-                setRowIndex(nextRowIndex);
+                // TODO: Double-check if this cast is safe. It should be...
+                E data = (E) getRowData();
                 nextRowIndex++;
+                setRowIndex(nextRowIndex);
+                return data; 
                 
-                if (isRowAvailable())
-                {
-                    // TODO: Double-check if this cast is safe. It should be...
-                    return (E) getRowData();
-                }
-                else
-                {
-                    nextRowIndex--;
-                }
             }
             
             throw new NoSuchElementException("Couldn't find any element in DataModel at index " + nextRowIndex);

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/model/ResultSetDataModel.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/model/ResultSetDataModel.java?rev=1155049&r1=1155048&r2=1155049&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/model/ResultSetDataModel.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/model/ResultSetDataModel.java Mon Aug  8 18:38:37 2011
@@ -269,14 +269,15 @@ public class ResultSetDataModel extends 
         @Override
         public boolean containsValue(Object value)
         {
-            for (String key : keySet())
+            //Iterate over entry set is better, because an entry
+            //key could have null value.
+            for (Map.Entry<String, Object> entry : entrySet())
             {
-                Object object = get(key);
-                if (object == null)
+                if (value != null && value.equals(entry.getValue()))
                 {
-                    return value == null;
+                    return true;
                 }
-                else if (object.equals(value))
+                else if (value == null && entry.getValue() == null)
                 {
                     return true;
                 }