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/02/08 02:37:48 UTC
svn commit: r619729 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry/corelib/components/
main/java/org/apache/tapestry/internal/grid/
main/java/org/apache/tapestry/internal/structure/ test/app1/
test/java/org/apache/tapes...
Author: hlship
Date: Thu Feb 7 17:37:46 2008
New Revision: 619729
URL: http://svn.apache.org/viewvc?rev=619729&view=rev
Log:
TAPESTRY-1901: Grid component calls prepare() and getRowValue() with incorrect values after items are removed
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DeleteFromGridDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/DeleteFromGridDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Grid.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridRemoveReorderDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Grid.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Grid.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Grid.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Grid.java Thu Feb 7 17:37:46 2008
@@ -258,10 +258,20 @@
}
}
+
+ int maxPage = ((availableRows - 1) / _rowsPerPage) + 1;
+
+ // This captures when the number of rows has decreased, typically due to deletions.
+
+ if (_currentPage > maxPage)
+ _currentPage = maxPage;
+
int startIndex = (_currentPage - 1) * _rowsPerPage;
+
int endIndex = Math.min(startIndex + _rowsPerPage - 1, availableRows - 1);
_source.prepare(startIndex, endIndex, sortModel, _sortAscending);
+
}
Object beginRender()
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java Thu Feb 7 17:37:46 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// 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.
@@ -34,7 +34,7 @@
{
notNull(collection, "collection");
- // Copy the collection so that we can sort it without distubing the original
+ // Copy the collection so that we can sort it without disturbing the original
_list = newList(collection);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java Thu Feb 7 17:37:46 2008
@@ -988,6 +988,12 @@
String currentEventType = eventType;
EventContext currentContext = context;
+ // Track the location of the original component for the event, even as we work our way up
+ // the hierarchy. This may not be ideal if we trigger an "exception" event ... or maybe
+ // it's right (it's the location of the originally thrown exception).
+
+ Location location = component.getComponentResources().getLocation();
+
while (component != null)
{
try
@@ -1008,8 +1014,6 @@
// We know component is not null and therefore has a component resources that
// should have a location.
-
- Location location = component.getComponentResources().getLocation();
// Wrap it up to help ensure that a location is available to the event handler method or,
// more likely, to the exception report page.
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DeleteFromGridDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DeleteFromGridDemo.tml?rev=619729&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DeleteFromGridDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DeleteFromGridDemo.tml Thu Feb 7 17:37:46 2008
@@ -0,0 +1,15 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>ToDo Listing</h1>
+
+ <t:grid rowsperpage="5" source="items" row="item">
+ <t:parameter name="titlecell">
+ <t:actionlink t:id="delete" context="item.id">${item.title}</t:actionlink>
+ </t:parameter>
+ </t:grid>
+
+ <p>
+ <t:actionlink t:id="setup">setup the database</t:actionlink>
+ </p>
+
+</html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridRemoveReorderDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridRemoveReorderDemo.tml?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridRemoveReorderDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridRemoveReorderDemo.tml Thu Feb 7 17:37:46 2008
@@ -1,11 +1,11 @@
<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
-
+
<h1>Grid Remove/Reorder Demo</h1>
-
- <table t:type="Grid" source="tracks" row="track" remove="playCount" reorder="rating,title" >
+
+ <table t:id="grid" source="tracks" row="track" remove="playCount" reorder="rating,title">
<t:parameter name="ratingcell">
<t:outputRating rating="track.rating"/>
</t:parameter>
</table>
-
+
</html>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Thu Feb 7 17:37:46 2008
@@ -1607,4 +1607,22 @@
assertFieldValue("count", "");
assertText("value", "null");
}
+
+ /**
+ * TAPESTRY-1901
+ */
+ @Test
+ public void delete_rows_from_grid()
+ {
+ start("Delete From Grid", "setup the database", "2");
+
+ for (int i = 6; i <= 10; i++)
+ clickAndWait("link=ToDo #" + i);
+
+ // A rather clumsy way to ensure we're back on the first page.
+
+ for (int i = 1; i <= 5; i++)
+ assertTextPresent("ToDo #" + i);
+
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/DeleteFromGridDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/DeleteFromGridDemo.java?rev=619729&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/DeleteFromGridDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/DeleteFromGridDemo.java Thu Feb 7 17:37:46 2008
@@ -0,0 +1,61 @@
+// 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.tapestry.integration.app1.pages;
+
+import org.apache.tapestry.integration.app1.data.ToDoItem;
+import org.apache.tapestry.integration.app1.services.ToDoDatabase;
+import org.apache.tapestry.ioc.annotations.Inject;
+
+import java.util.List;
+
+public class DeleteFromGridDemo
+{
+ @Inject
+ private ToDoDatabase _database;
+
+ private ToDoItem _item;
+
+ void onActionFromSetup()
+ {
+ _database.clear();
+
+ for (int i = 1; i <= 10; i++)
+ {
+ ToDoItem item = new ToDoItem();
+ item.setTitle(String.format("ToDo #%d", i));
+ item.setOrder(i);
+
+ _database.add(item);
+ }
+ }
+
+ void onActionFromDelete(long id)
+ {
+ _database.remove(id);
+ }
+
+ public List<ToDoItem> getItems() { return _database.findAll(); }
+
+ public ToDoItem getItem()
+ {
+ return _item;
+ }
+
+ public void setItem(ToDoItem item)
+ {
+ _item = item;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java Thu Feb 7 17:37:46 2008
@@ -61,6 +61,8 @@
private static final List<Item> ITEMS = CollectionFactory.newList(
new Item("actionpage", "Action Page", "tests fixture for ActionLink component"),
+ new Item("DeleteFromGridDemo", "Delete From Grid", "demo deleting items form a Grid"),
+
new Item("RenderErrorDemo", "Render Error Demo", "reporting of errors while rendering"),
new Item("nested/AssetDemo", "AssetDemo", "declaring an image using Assets"),
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java Thu Feb 7 17:37:46 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// 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.
@@ -47,4 +47,12 @@
* Deletes all items from the database.
*/
void clear();
+
+ /**
+ * Removes an existing item
+ *
+ * @param itemId item to remove
+ * @throws RuntimeException if the item does not exist
+ */
+ void remove(long itemId);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java?rev=619729&r1=619728&r2=619729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java Thu Feb 7 17:37:46 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// 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.
@@ -47,6 +47,7 @@
_items.clear();
}
+
public void reset()
{
_items.clear();
@@ -105,5 +106,14 @@
_items.put(id, item.clone());
}
+
+ public void remove(long itemId)
+ {
+ ToDoItem item = _items.remove(itemId);
+
+ if (item == null)
+ throw new RuntimeException(String.format("ToDoItem #%d not found.", itemId));
+ }
+
}