Paulo Gaspar wrote:
> Yes, you get Iterator's from object arrays, Collection's and Map's ...
> ...but what happens if the object to iterate trough in the #foreach is
> _already_ an Iterator???
Thinking about this, allowing an Iterator will lead to trouble -
code (vec is a Vector) :
context.put("iterator", vec.iterator() );
template :
#foreach($i in $iterator)
$i
#end
#foreach($j in $iterator)
$j
#end
Will result in a surprise... there's no way to 'reset' the Iterator, so
the second foreach loop wouldn't output anything.
This is a problem.
I think we shouldn't allow using Iterator's directly in the context, as
this will simply lead to trouble - no matter how well documented, this
kind of statefulness w.o. the ability to reset will lead to problems for
people.
I can put a message in the log if we come across an Iterator with a
warning, because it *is* sort of a natural thing to do, but we should
probably try to dissuade people from using this.
Comments, anyone?
geir
--
Geir Magnusson Jr. [EMAIL PROTECTED]
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity