Author: niallp
Date: Tue Apr  5 22:55:41 2005
New Revision: 160255

URL: http://svn.apache.org/viewcvs?view=rev&rev=160255
Log:
Bug 32778 HTML Link Tag does not work with JSTL Loop Tag

Modified:
    
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java?view=diff&r1=160254&r2=160255
==============================================================================
--- 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java 
(original)
+++ 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java 
Tue Apr  5 22:55:41 2005
@@ -669,44 +669,47 @@
      */
     protected void prepareIndex(StringBuffer handlers, String name)
         throws JspException {
-        int index = 0;
-        boolean found = false;
-
-        // look for outer iterate tag
-        IterateTag iterateTag =
-            (IterateTag) findAncestorWithClass(this, IterateTag.class);
-
-        // Look for JSTL loops
-        if (iterateTag == null) {
-            Integer i = getJstlLoopIndex();
-            if (i != null) {
-                index = i.intValue();
-                found = true;
-            }
-
-        } else {
-            index = iterateTag.getIndex();
-            found = true;
-        }
-
-        if (!found) {
-            // this tag should only be nested in iteratetag, if it's not, 
throw exception
-            JspException e =
-                new 
JspException(messages.getMessage("indexed.noEnclosingIterate"));
-            TagUtils.getInstance().saveException(pageContext, e);
-            throw e;
-        }
 
         if (name != null) {
             handlers.append(name);
         }
 
         handlers.append("[");
-        handlers.append(index);
+        handlers.append(getIndexValue());
         handlers.append("]");
+
         if (name != null) {
             handlers.append(".");
         }
+    }
+
+    /**
+     *  Appends bean name with index in brackets for tags with
+     *  'true' value in 'indexed' attribute.
+     *  @param handlers The StringBuffer that output will be appended to.
+     *  @exception JspException if 'indexed' tag used outside of iterate tag.
+     */
+    protected int getIndexValue() throws JspException {
+
+        // look for outer iterate tag
+        IterateTag iterateTag =
+            (IterateTag) findAncestorWithClass(this, IterateTag.class);
+        if (iterateTag != null) {
+            return iterateTag.getIndex();
+        }
+
+        // Look for JSTL loops
+        Integer i = getJstlLoopIndex();
+        if (i != null) {
+            return i.intValue();
+        }
+
+        // this tag should be nested in an IterateTag or JSTL loop tag, if 
it's not, throw exception
+        JspException e =
+             new 
JspException(messages.getMessage("indexed.noEnclosingIterate"));
+        TagUtils.getInstance().saveException(pageContext, e);
+        throw e;
+
     }
 
     /**

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java?view=diff&r1=160254&r2=160255
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java Tue 
Apr  5 22:55:41 2005
@@ -402,6 +402,7 @@
         name = null;
         page = null;
         action = null;
+        module = null;
         paramId = null;
         paramName = null;
         paramProperty = null;
@@ -411,6 +412,8 @@
         target = null;
         text = null;
         transaction = false;
+        indexId = null;
+        useLocalEncoding = false;
 
     }
 
@@ -435,26 +438,16 @@
         // * @since Struts 1.1
         if( indexed ) {
 
-           // look for outer iterate tag
-           IterateTag iterateTag =
-               (IterateTag) findAncestorWithClass(this, IterateTag.class);
-           if (iterateTag == null) {
-               // This tag should only be nested in an iterate tag
-               // If it's not, throw exception
-               JspException e = new JspException
-                   (messages.getMessage("indexed.noEnclosingIterate"));
-               TagUtils.getInstance().saveException(pageContext, e);
-               throw e;
-           }
+           int indexValue = getIndexValue();
 
            //calculate index, and add as a parameter
            if (params == null) {
                params = new HashMap();             //create new HashMap if no 
other params
            }
            if (indexId != null) {
-            params.put(indexId, Integer.toString(iterateTag.getIndex()));
+              params.put(indexId, Integer.toString(indexValue));
            } else {
-              params.put("index", Integer.toString(iterateTag.getIndex()));
+              params.put("index", Integer.toString(indexValue));
            }
         }
 



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

Reply via email to