DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14683>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14683

add get/setIterator methods to IterateTag

           Summary: add get/setIterator methods to IterateTag
           Product: Struts
           Version: Nightly Build
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Custom Tags
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


By adding get/setIterator methods to the
org.apache.struts.taglib.logic.IterateTag class and using those in that class,
it will allow developers to override the iterate functionality without changing
the code on the custom tag methods that actually do the iterating.

We have a need to filter what is iterated in several different places in our
application.  Without adding logic in our jsp's to filter out content in a list,
and without filtering out the list in the action maintaining the index in the
second list against the index in the first list, the best place it seems to
filter would be to override the Iterator functionality with the filtering done
in there.

I am currently having to subclass the Struts IterateTag doAfterBody() method.
Changing this could possibly introduce a bug in the way struts iterates over the
  Collection. It would be cleaner to change the underlying iterator without
changing the calls to iterate over the collection.

Attached is a patch that adds a get/setIterate methods and updates all the
references to iterator with the respective get/setIterator.


Index: IterateTag.java
===================================================================
RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v
retrieving revision 1.16
diff -u -r1.16 IterateTag.java
--- IterateTag.java     23 Sep 2002 05:22:08 -0000      1.16
+++ IterateTag.java     19 Nov 2002 16:10:14 -0000
@@ -96,13 +96,6 @@
 
 
     /**
-     * Iterator of the elements of this collection, while we are actually
-     * running.
-     */
-    protected Iterator iterator = null;
-
-
-    /**
      * The number of elements we have already rendered.
      */
     protected int lengthCount = 0;
@@ -137,6 +130,23 @@
 
     // ------------------------------------------------------------- Properties
 
+    /**
+     * Iterator of the elements of this collection, while we are actually
+     * running.
+     */
+    protected Iterator iterator = null;
+
+    public Iterator getIterator() {
+        return iterator;
+    }
+
+    public void setIterator(Iterator iterator) {
+        this.iterator = iterator;
+    }
+
+
+
+
 
     /**
      * The collection over which we will be iterating.
@@ -312,7 +322,7 @@
             try {
                 // If we're lucky, it is an array of objects
                 // that we can iterate over with no copying
-                iterator = Arrays.asList((Object[]) collection).iterator();
+                setIterator(Arrays.asList((Object[]) collection).iterator());
             } catch (ClassCastException e) {
                 // Rats -- it is an array of primitives
                 int length = Array.getLength(collection);
@@ -320,16 +330,16 @@
                 for (int i = 0; i < length; i++) {
                     c.add(Array.get(collection, i));
                 }
-                iterator = c.iterator();
+                setIterator(c.iterator());
             }
        } else if (collection instanceof Collection)
-           iterator = ((Collection) collection).iterator();
+           setIterator(((Collection) collection).iterator());
        else if (collection instanceof Iterator)
-           iterator = (Iterator) collection;
+           setIterator((Iterator) collection);
        else if (collection instanceof Map)
-           iterator = ((Map) collection).entrySet().iterator();
+           setIterator(((Map) collection).entrySet().iterator());
         else if (collection instanceof Enumeration)
-           iterator = new IteratorAdapter((Enumeration)collection);
+           setIterator(new IteratorAdapter((Enumeration)collection));
        else {
            JspException e = new JspException
                (messages.getMessage("iterate.iterator"));
@@ -376,14 +386,14 @@
 
        // Skip the leading elements up to the starting offset
        for (int i = 0; i < offsetValue; i++) {
-           if (iterator.hasNext()) {
-               Object element = iterator.next();
+           if (getIterator().hasNext()) {
+               Object element = getIterator().next();
            }
        }
 
        // Store the first value and evaluate, or skip the body if none
-       if (iterator.hasNext()) {
-           Object element = iterator.next();
+       if (getIterator().hasNext()) {
+           Object element = getIterator().next();
             if (element == null)
                 pageContext.removeAttribute(id);
             else
@@ -416,8 +426,8 @@
         // Decide whether to iterate or quit
        if ((lengthValue > 0) && (lengthCount >= lengthValue))
            return (SKIP_BODY);
-       if (iterator.hasNext()) {
-           Object element = iterator.next();
+       if (getIterator().hasNext()) {
+           Object element = getIterator().next();
             if (element == null)
                 pageContext.removeAttribute(id);
             else

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to