You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/07/29 23:36:59 UTC
svn commit: r680849 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/components/
main/java/org/apache/tapestry5/grid/ test/app1/
test/java/org/apache/tapestry5/integration/
test/java/org/apache/tapestry5/integrat...
Author: hlship
Date: Tue Jul 29 14:36:58 2008
New Revision: 680849
URL: http://svn.apache.org/viewvc?rev=680849&view=rev
Log:
TAPESTRY-2502: When the GridDataSource reports more available rows than actual rows (due to race conditions with updates), the Grid will fail because of IndexOutOfRange exceptions
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShortGrid.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShortGrid.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java?rev=680849&r1=680848&r2=680849&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java Tue Jul 29 14:36:58 2008
@@ -11,6 +11,19 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
package org.apache.tapestry5.corelib.components;
@@ -199,7 +212,7 @@
}
- void beginRender()
+ boolean beginRender()
{
// When needed, store a callback used when the form is submitted.
@@ -208,13 +221,22 @@
// And do it now for the render.
setupForRow(rowIndex);
+
+ // If the row is null, it's because the rowIndex is too large (see the notes
+ // on GridDataSource). When row is null, return false to not render anything for this iteration
+ // of the loop.
+
+ return row != null;
}
boolean afterRender()
{
rowIndex++;
- return rowIndex > endRow;
+ // Abort the loop when we hit a null row, or when we've exhausted the range we need to
+ // display.
+
+ return row == null || rowIndex > endRow;
}
public List<String> getPropertyNames()
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java?rev=680849&r1=680848&r2=680849&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java Tue Jul 29 14:36:58 2008
@@ -39,7 +39,10 @@
void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints);
/**
- * Returns the row value at the provided index. This method will be invoked in sequential order.
+ * Returns the row value at the provided index. This method will be invoked in sequential order. In rare instances,
+ * {@link #getAvailableRows()} may return a different number of rows than are actually available (i.e., the database
+ * was changed between calls to {@link #getAvailableRows()} and the call to {@link #prepare(int, int,
+ * java.util.List)}). In that case, this method should return null for any out-of-range indexes.
*/
Object getRowValue(int index);
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShortGrid.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShortGrid.tml?rev=680849&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShortGrid.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShortGrid.tml Tue Jul 29 14:36:58 2008
@@ -0,0 +1,11 @@
+<html t:type="border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>Short Grid</h1>
+
+ <p>
+ Only items with index 0 to 5 should appear. After that, the GridDataSource returns null.
+ </p>
+
+ <t:grid id="grid" source="data"/>
+
+</html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=680849&r1=680848&r2=680849&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java Tue Jul 29 14:36:58 2008
@@ -2101,4 +2101,25 @@
assertTextPresent(
"Component class org.apache.tapestry5.integration.app1.pages.Music may not be instantiated directly.");
}
+
+ /**
+ * TAPESTRY-2502
+ */
+ @Test
+ public void short_grid()
+ {
+ start("Short Grid");
+
+ for (int i = 0; i < 6; i++)
+ {
+ String locator = String.format("grid.%d.0", i + 1);
+ String expected = String.format("Index #%d", i);
+
+ assertEquals(getTable(locator), expected);
+ }
+
+ String count = getEval("window.document.getElementById('grid').rows.length");
+
+ assertEquals(count, "7", "Expected seven rows: the header and six data rows.");
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShortGrid.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShortGrid.java?rev=680849&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShortGrid.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShortGrid.java Tue Jul 29 14:36:58 2008
@@ -0,0 +1,57 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.grid.GridDataSource;
+import org.apache.tapestry5.grid.SortConstraint;
+import org.apache.tapestry5.integration.app1.data.ToDoItem;
+
+import java.util.List;
+
+public class ShortGrid
+{
+ public GridDataSource getData()
+ {
+ return new GridDataSource()
+ {
+ public int getAvailableRows()
+ {
+ return 50;
+ }
+
+ public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints)
+ {
+ }
+
+ public Object getRowValue(int index)
+ {
+ if (index > 5) return null;
+
+
+ ToDoItem item = new ToDoItem();
+
+ item.setTitle("Index #" + index);
+
+ return item;
+
+ }
+
+ public Class getRowType()
+ {
+ return ToDoItem.class;
+ }
+ };
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=680849&r1=680848&r2=680849&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java Tue Jul 29 14:36:58 2008
@@ -62,6 +62,9 @@
private static final List<Item> ITEMS = CollectionFactory.newList(
+ new Item("ShortGrid", "Short Grid",
+ "Grid where the number of claimed rows is less than the number of actual rows"),
+
new Item("NullParameterDemo", "Null Parameter Demo", "Binding a not-null parameter to null."),
new Item("nestedbeaneditor", "Nested BeanEditor",