Bug 44284 - Support java.lang.Iterable in c:forEach tag
Summary: Support java.lang.Iterable in c:forEach tag
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 6.0.14
Hardware: Other other
: P2 enhancement (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2008-01-23 05:18 UTC by James
Modified: 2012-10-31 17:49 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James 2008-01-23 05:18:50 UTC
---
apache-tomcat-6.0.10-src/java/org/apache/jasper/tagplugins/jstl/core/ForEach.java
  Tue Feb 13 05:04:52 2007
+++ webapp/WEB-INF/classes/org/apache/jasper/tagplugins/jstl/core/ForEach.java 
Fri Mar  2 09:07:07 2007
@@ -137,9 +137,9 @@
         ctxt.generateJavaSource("else if (" + itemsV + " instanceof double[])");
         ctxt.generateJavaSource(iterV + "=toIterator((double[])" + itemsV + ");");
         
-        // Collection
-        ctxt.generateJavaSource("else if (" + itemsV + " instanceof Collection)");
-        ctxt.generateJavaSource(iterV + "=((Collection)" + itemsV +
").iterator();");
+        // Iterable
+        ctxt.generateJavaSource("else if (" + itemsV + " instanceof Iterable)");
+        ctxt.generateJavaSource(iterV + "=((Iterable)" + itemsV + ").iterator();");
         
         // Iterator
         ctxt.generateJavaSource("else if (" + itemsV + " instanceof Iterator)");





---
jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ForEachSupport.java
       Tue Aug 29 01:13:06 2006
+++
webapp/WEB-INF/classes/org/apache/taglibs/standard/tag/common/core/ForEachSupport.java
     Fri Mar  2 09:21:06 2007
@@ -17,7 +17,6 @@
 package org.apache.taglibs.standard.tag.common.core;
 
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Map;
@@ -201,8 +200,8 @@
             items = toForEachIterator((float[]) o);
         else if (o instanceof double[])
             items = toForEachIterator((double[]) o);
-        else if (o instanceof Collection)
-            items = toForEachIterator((Collection) o);
+        else if (o instanceof Iterable)
+            items = toForEachIterator((Iterable) o);
         else if (o instanceof Iterator)
             items = toForEachIterator((Iterator) o);
         else if (o instanceof Enumeration)
@@ -324,8 +323,8 @@
         return new SimpleForEachIterator(Arrays.asList(wrapped).iterator());
     }
 
-    // retrieves an iterator from a Collection
-    protected ForEachIterator toForEachIterator(Collection c) {
+    // retrieves an iterator from a Iterable
+    protected ForEachIterator toForEachIterator(Iterable c) {
         return new SimpleForEachIterator(c.iterator());
     }
Comment 1 Jess Holle 2011-05-01 14:01:19 UTC
Overall I'm confused by the state of JSTL with Tomcat.  The only clear/obvious place to get an up-to-date JSTL (including for use with Tomcat) is the Glassfish site.
Comment 2 Christopher Schultz 2012-08-13 14:47:41 UTC
The JSTL spec requires that "items" that are of type "array", java.util.Collection, java.util.Iterator, java.util.Enumeration, java.util.Map, and String be supported by forEach implementations. I don't see anything that suggests that support for /other/ types should be prohibited.

My only concern would be that of portability of the JSP that uses an implementation that supports Iterable: other implementations may not support it, so the Tomcat implementation would effectively fragment the standard.

It should be easy write a method that accepts an Iterable and returns an Iterator, and then wrap your Iterable objects in a call to that method before passing it into the <c:forEach> tag. That seems like a more portable solution.
Comment 3 Mark Thomas 2012-10-27 17:19:51 UTC
I am resolving this as WONTFIX due to the portability issues raised by Chris.

To answer Jesse's question, Apache's JSTL project was part of Jakarta and it moved to Tomcat when Jakarta was dis-banded. There has been very little progress since and - absent some renewed interest - the work will be formally placed in the attic shortly. I believe there isn't too much work required to get to a complete 1.2 release but the current developers are unlikely to find sufficient time to complete this work.

Tomcat's plug-in implementation has seen very little (make that no) love for many years and only covers the core 1.1 tags. There has been some renewed interest recently but so far that has been around bug fixes and performance improvements - not 1.2 or additional tags.
Comment 4 Christopher Schultz 2012-10-31 17:49:44 UTC
I think just about everyone uses Glassfish's JSTL implementation, anyway, right?