You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/03/20 00:52:42 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/directive Foreach.java
geirm 01/03/19 15:52:42
Modified: src/java/org/apache/velocity/runtime/directive Foreach.java
Log:
Small fix : we didn't handle nested #foreach() loops correctly. Whoops.
Revision Changes Path
1.34 +25 -4 jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Foreach.java
Index: Foreach.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Foreach.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- Foreach.java 2001/03/19 17:12:58 1.33
+++ Foreach.java 2001/03/19 23:52:41 1.34
@@ -84,7 +84,7 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: Foreach.java,v 1.33 2001/03/19 17:12:58 geirm Exp $
+ * @version $Id: Foreach.java,v 1.34 2001/03/19 23:52:41 geirm Exp $
*/
public class Foreach extends Directive
{
@@ -298,10 +298,12 @@
int counter = COUNTER_INITIAL_VALUE;
/*
- * save the element key if there is one
+ * save the element key if there is one,
+ * and the loop counter
*/
Object o = context.get( elementKey );
+ Object ctr = context.get( COUNTER_NAME );
while (i.hasNext())
{
@@ -311,15 +313,34 @@
counter++;
}
- context.remove(COUNTER_NAME);
- context.remove(elementKey);
+ /*
+ * restores the loop counter (if we were nested)
+ * if we have one, else just removes
+ */
+
+ if( ctr != null)
+ {
+ context.put( COUNTER_NAME, ctr );
+ }
+ else
+ {
+ context.remove(COUNTER_NAME);
+ }
+
/*
* restores element key if exists
+ * otherwise just removes
*/
if (o != null)
+ {
context.put( elementKey, o );
+ }
+ else
+ {
+ context.remove(elementKey);
+ }
return true;
}