You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/12/20 20:21:13 UTC

svn commit: r606005 - in /tapestry/tapestry5/trunk: ./ tapestry-core/src/main/java/org/apache/tapestry/internal/grid/ tapestry-core/src/main/java/org/apache/tapestry/services/ tapestry-core/src/test/app1/ tapestry-core/src/test/java/org/apache/tapestry...

Author: hlship
Date: Thu Dec 20 11:21:10 2007
New Revision: 606005

URL: http://svn.apache.org/viewvc?rev=606005&view=rev
Log:
TAPESTRY-1925: Obscure exception when a Collection (not a List) is used as a GridDataSource

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java
      - copied, changed from r594319, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/ListGridDataSource.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridSetDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/GridSetDemo.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/CollectionGridDataSourceTest.java
      - copied, changed from r594319, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/ListGridDataSourceTest.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry5.ipr

Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java (from r594319, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/ListGridDataSource.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/ListGridDataSource.java&r1=594319&r2=606005&rev=606005&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/ListGridDataSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/grid/CollectionGridDataSource.java Thu Dec 20 11:21:10 2007
@@ -20,22 +20,23 @@
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-public class ListGridDataSource implements GridDataSource
+public class CollectionGridDataSource implements GridDataSource
 {
     private final List _list;
 
     @SuppressWarnings("unchecked")
-    public ListGridDataSource(final List list)
+    public CollectionGridDataSource(final Collection collection)
     {
-        notNull(list, "list");
+        notNull(collection, "collection");
 
-        // Copy the list so that we can sort it without distubing the original
+        // Copy the collection so that we can sort it without distubing the original
 
-        _list = newList(list);
+        _list = newList(collection);
     }
 
     public int getAvailableRows()
@@ -44,11 +45,9 @@
     }
 
     @SuppressWarnings("unchecked")
-    public void prepare(int startIndex, int endIndex, PropertyModel sortModel,
-                        final boolean ascending)
+    public void prepare(int startIndex, int endIndex, PropertyModel sortModel, final boolean ascending)
     {
-        if (sortModel == null)
-            return;
+        if (sortModel == null) return;
 
         final PropertyConduit conduit = sortModel.getConduit();
 
@@ -58,14 +57,11 @@
             {
                 // Simplify comparison, and handle case where both are nulls.
 
-                if (o1 == o2)
-                    return 0;
+                if (o1 == o2) return 0;
 
-                if (o2 == null)
-                    return 1;
+                if (o2 == null) return 1;
 
-                if (o1 == null)
-                    return -1;
+                if (o1 == null) return -1;
 
                 return o1.compareTo(o2);
             }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=606005&r1=606004&r2=606005&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Thu Dec 20 11:21:10 2007
@@ -26,7 +26,7 @@
 import org.apache.tapestry.internal.beaneditor.ValidateAnnotationConstraintGenerator;
 import org.apache.tapestry.internal.bindings.*;
 import org.apache.tapestry.internal.events.InvalidationListener;
-import org.apache.tapestry.internal.grid.ListGridDataSource;
+import org.apache.tapestry.internal.grid.CollectionGridDataSource;
 import org.apache.tapestry.internal.grid.NullDataSource;
 import org.apache.tapestry.internal.services.*;
 import org.apache.tapestry.internal.util.IntegerRange;
@@ -598,7 +598,7 @@
      * <ul>
      * <li>String to {@link SelectModel}
      * <li>Map to {@link SelectModel}
-     * <li>List to {@link GridDataSource}
+     * <li>Collection to {@link GridDataSource}
      * <li>null to {@link GridDataSource}
      * <li>String to {@link GridPagerPosition}
      * <li>List to {@link SelectModel}
@@ -624,11 +624,11 @@
             }
         });
 
-        add(configuration, List.class, GridDataSource.class, new Coercion<List, GridDataSource>()
+        add(configuration, Collection.class, GridDataSource.class, new Coercion<Collection, GridDataSource>()
         {
-            public GridDataSource coerce(List input)
+            public GridDataSource coerce(Collection input)
             {
-                return new ListGridDataSource(input);
+                return new CollectionGridDataSource(input);
             }
         });
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridSetDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridSetDemo.tml?rev=606005&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridSetDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridSetDemo.tml Thu Dec 20 11:21:10 2007
@@ -0,0 +1,11 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+    <h1>Grid Set Demo</h1>
+
+    <table t:type="Grid" source="tracks" row="track">
+        <t:parameter name="ratingcell">
+            <t:outputRating rating="track.rating"/>
+        </t:parameter>
+    </table>
+
+</html>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=606005&r1=606004&r2=606005&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Thu Dec 20 11:21:10 2007
@@ -155,6 +155,10 @@
                         -- handling of null source for Grid
                     </li>
                     <li>
+                        <a t:type="PageLink" page="gridsetdemo">Grid Set Demo</a>
+                        -- handling of Set sources for Grid
+                    </li>
+                    <li>
                         <a t:type="PageLink" page="gridenumdemo">Grid Enum Demo</a>
                         -- handling of enum types in the Grid
                     </li>

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=606005&r1=606004&r2=606005&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 Dec 20 11:21:10 2007
@@ -687,6 +687,14 @@
     }
 
     @Test
+    public void grid_set() throws Exception
+    {
+        start("Grid Set Demo");
+
+        assertFalse(isTextPresent("Exception"));
+    }
+
+    @Test
     public void navigation_response_from_page_activate() throws Exception
     {
         start("Protected Page");

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/GridSetDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/GridSetDemo.java?rev=606005&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/GridSetDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/GridSetDemo.java Thu Dec 20 11:21:10 2007
@@ -0,0 +1,45 @@
+// Copyright 2007 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.Track;
+import org.apache.tapestry.integration.app1.services.MusicLibrary;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+
+import java.util.Set;
+
+public class GridSetDemo
+{
+    @Inject
+    private MusicLibrary _library;
+
+    private Track _track;
+
+    public Track getTrack()
+    {
+        return _track;
+    }
+
+    public void setTrack(Track track)
+    {
+        _track = track;
+    }
+
+    public Set<Track> getTracks()
+    {
+        return CollectionFactory.newSet(_library.getTracks());
+    }
+}

Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/CollectionGridDataSourceTest.java (from r594319, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/ListGridDataSourceTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/CollectionGridDataSourceTest.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/CollectionGridDataSourceTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/ListGridDataSourceTest.java&r1=594319&r2=606005&rev=606005&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/ListGridDataSourceTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/grid/CollectionGridDataSourceTest.java Thu Dec 20 11:21:10 2007
@@ -27,7 +27,7 @@
 import java.util.Arrays;
 import java.util.List;
 
-public class ListGridDataSourceTest extends InternalBaseTestCase
+public class CollectionGridDataSourceTest extends InternalBaseTestCase
 {
     // Just arbitrary numbers ...
 
@@ -41,13 +41,10 @@
 
     // Arrays.asList returns an unmodifiable list
 
-    private final List _raw = Arrays.asList(
-            new Datum(FRED, "Fred"),
-            new Datum(BARNEY, "Barney"),
-            new Datum(WILMA, "Wilma"),
-            new Datum(BETTY, null));
+    private final List _raw = Arrays.asList(new Datum(FRED, "Fred"), new Datum(BARNEY, "Barney"),
+                                            new Datum(WILMA, "Wilma"), new Datum(BETTY, null));
 
-    private final ListGridDataSource _source = new ListGridDataSource(_raw);
+    private final CollectionGridDataSource _source = new CollectionGridDataSource(_raw);
 
     private BeanModel _model;
 

Modified: tapestry/tapestry5/trunk/tapestry5.ipr
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry5.ipr?rev=606005&r1=606004&r2=606005&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry5.ipr (original)
+++ tapestry/tapestry5/trunk/tapestry5.ipr Thu Dec 20 11:21:10 2007
@@ -88,11 +88,7 @@
     <autodetection-disabled>
       <facet-type id="web">
         <modules>
-          <module name="tutorial1">
-            <files>
-              <file url="file://$PROJECT_DIR$/tapestry-tutorial1/src/main/webapp/WEB-INF/web.xml" />
-            </files>
-          </module>
+          <module name="tutorial1" />
           <module name="quickstart">
             <files>
               <file url="file://$PROJECT_DIR$/quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml" />