diff --git a/src/com/christophermrossi/jpt/Loop.java b/src/com/christophermrossi/jpt/Loop.java index 183d1c0..5970e69 100644 --- a/src/com/christophermrossi/jpt/Loop.java +++ b/src/com/christophermrossi/jpt/Loop.java @@ -37,6 +37,7 @@ public class Loop { Iterator iterator; int index = -1; int length = -1; + Loop loopParent = null; Loop( String expression, Interpreter beanShell ) throws PageTemplateException { if ( expression == null ) { @@ -90,7 +91,7 @@ void addToRepeat( Interpreter beanShell ) throws PageTemplateException { repeat = new TreeMap(); beanShell.set( "repeat", repeat ); } - repeat.put( this.variableName, this ); + this.loopParent = (Loop)repeat.put( this.variableName, this ); } catch( bsh.EvalError e ) { throw new PageTemplateException(e); } @@ -99,7 +100,13 @@ void addToRepeat( Interpreter beanShell ) throws PageTemplateException { void removeFromRepeat( Interpreter beanShell ) throws PageTemplateException { try { Map repeat = (Map)beanShell.get( "repeat" ); - repeat.remove( this.variableName ); + if ( this.loopParent == null ) { + repeat.remove( this.variableName ); + } + else { + repeat.put( this.variableName, this.loopParent ); + this.loopParent = null; + } if ( repeat.size() == 0 ) { beanShell.unset( "repeat" ); } diff --git a/test/com/christophermrossi/jpt/statements.html b/test/com/christophermrossi/jpt/statements.html index f18e659..231f5ad 100644 --- a/test/com/christophermrossi/jpt/statements.html +++ b/test/com/christophermrossi/jpt/statements.html @@ -1766,9 +1766,92 @@

This is a test

+

+ Let's try a nested loop using the same loop variable name. + Apparently if you use recursive macros, something I've never + done, you will need for this to work. Use case courtesy of + James Davies. + + +

4
+ + + + + +
4
+ + +
+ + +
2
+ + +
+ +

+

4

- - diff --git a/test/com/christophermrossi/jpt/statements.jpt b/test/com/christophermrossi/jpt/statements.jpt index bb442bd..05b680c 100644 --- a/test/com/christophermrossi/jpt/statements.jpt +++ b/test/com/christophermrossi/jpt/statements.jpt @@ -113,6 +113,20 @@ properly.

+

+ Let's try a nested loop using the same loop variable name. + Apparently if you use recursive macros, something I've never + done, you will need for this to work. Use case courtesy of + James Davies. + +

+ + +

Joe Mama