]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged:
authorArtur Signell <artur.signell@itmill.com>
Mon, 27 Apr 2009 13:04:15 +0000 (13:04 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 27 Apr 2009 13:04:15 +0000 (13:04 +0000)
Fix for #2864 - Added server side checks for currentPageFirstItemId & currentPageFirstItemIndex validity

svn changeset:7535/svn branch:6.0

src/com/itmill/toolkit/ui/Table.java

index 4d4fdba7fb50eee78c934c6bbacee7e5c3345539..083b393aa80003523c573392ac8b30381800c285 100644 (file)
@@ -822,8 +822,23 @@ public class Table extends AbstractSelect implements Action.Container,
             }
         }
 
-        // If the search for item index was successfull
+        // If the search for item index was successful
         if (index >= 0) {
+            /*
+             * The table is not capable of displaying an item in the container
+             * as the first if there are not enough items following the selected
+             * item so the whole table (pagelength) is filled.
+             */
+            int maxIndex = size() - pageLength;
+            if (maxIndex < 0) {
+                maxIndex = 0;
+            }
+
+            if (index > maxIndex) {
+                setCurrentPageFirstItemIndex(maxIndex);
+                return;
+            }
+
             this.currentPageFirstItemId = currentPageFirstItemId;
             currentPageFirstItemIndex = index;
         }
@@ -1087,14 +1102,26 @@ public class Table extends AbstractSelect implements Action.Container,
 
     private void setCurrentPageFirstItemIndex(int newIndex,
             boolean needsPageBufferReset) {
-        // Ensures that the new value is valid
-        if (newIndex >= size()) {
-            newIndex = size() - pageLength;
-        }
+
         if (newIndex < 0) {
             newIndex = 0;
         }
 
+        /*
+         * The table is not capable of displaying an item in the container as
+         * the first if there are not enough items following the selected item
+         * so the whole table (pagelength) is filled.
+         */
+        int maxIndex = size() - pageLength;
+        if (maxIndex < 0) {
+            maxIndex = 0;
+        }
+
+        // Ensures that the new value is valid
+        if (newIndex > maxIndex) {
+            newIndex = maxIndex;
+        }
+
         // Refresh first item id
         if (items instanceof Container.Indexed) {
             try {