craigmcc 01/04/18 15:05:04
Modified: doc struts-logic.xml
src/share/org/apache/struts/taglib/logic IterateTag.java
Log:
If the collection you are iterating over has null elements, the iteration
still occurs, but the current element is *not* exposed under the key named
by the "id" attribute. You can use <logic:present> and <logic:notPresent>
tags to detect this case appropriately.
PR: Bugzilla #706
Submitted by: Howard Moore <[EMAIL PROTECTED]>
Revision Changes Path
1.4 +8 -1 jakarta-struts/doc/struts-logic.xml
Index: struts-logic.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/doc/struts-logic.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- struts-logic.xml 2001/04/14 02:37:31 1.3
+++ struts-logic.xml 2001/04/18 22:04:59 1.4
@@ -432,6 +432,12 @@
</logic:iterate>
</code>
+ <p>If the collection you are iterating over can contain <code>null</code>
+ values, the loop will still be performed but no page scope attribute
+ (named by the <code>id</code> attribute) will be created for that loop
+ iteration. You can use the <code><logic:present></code> and
+ <code><logic:notPresent></code> tags to test for this case.</p>
+
<p><strong>WARNING</strong> - Currently, this tag cannot deal with
arrays of primitive data types. Only arrays of Java objects (including
Strings) are supported.</p>
@@ -453,7 +459,8 @@
<rtexprvalue>true</rtexprvalue>
<info>
<p>The name of a page scope JSP bean that will contain the current
- element of the collection on each iteration.</p>
+ element of the collection on each iteration, if it is not
+ <code>null</code>.</p>
</info>
</attribute>
1.10 +12 -6
jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java
Index: IterateTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- IterateTag.java 2001/03/31 22:27:30 1.9
+++ IterateTag.java 2001/04/18 22:05:02 1.10
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v
1.9 2001/03/31 22:27:30 rleland Exp $
- * $Revision: 1.9 $
- * $Date: 2001/03/31 22:27:30 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v
1.10 2001/04/18 22:05:02 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2001/04/18 22:05:02 $
*
* ====================================================================
*
@@ -88,7 +88,7 @@
* or a Map (which includes Hashtables) whose elements will be iterated over.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2001/03/31 22:27:30 $
+ * @version $Revision: 1.10 $ $Date: 2001/04/18 22:05:02 $
*/
public class IterateTag extends BodyTagSupport {
@@ -335,7 +335,10 @@
// Store the first value and evaluate, or skip the body if none
if (iterator.hasNext()) {
Object element = iterator.next();
- pageContext.setAttribute(id, element);
+ if (element == null)
+ pageContext.removeAttribute(id);
+ else
+ pageContext.setAttribute(id, element);
lengthCount++;
return (EVAL_BODY_TAG);
} else
@@ -363,7 +366,10 @@
return (SKIP_BODY);
if (iterator.hasNext()) {
Object element = iterator.next();
- pageContext.setAttribute(id, element);
+ if (element == null)
+ pageContext.removeAttribute(id);
+ else
+ pageContext.setAttribute(id, element);
lengthCount++;
return (EVAL_BODY_TAG);
} else