Avatar
Simplicity, Productivity and Organization Enthusiast.

Apache Velocity 1.6 Nested Loop Bug

I have just spent two hours of my evening trying to figure out an issue I had with Apache Velocity 1.6.

If you are using the #foreach loop, make sure that you are looping at only one level.

It seems that using nested #foreach on the same variable does not work with Apache Velocity 1.6.

For example:

#foreach ($item in $list)

#foreach ($item in $list)

#end

#end

will not work in 1.6. The issue has been solved in 1.7. See http://issues.apache.org/jira/browse/VELOCITY-658 for all the juicy details.

If you are stuck with 1.6 and you are using the java.util.Collection framework, then cloning your list using toArray() will do the trick.