$velocityHasNext not working properly (returns true even if iterator does not
have next value)
----------------------------------------------------------------------------------------------
Key: VELOCITY-657
URL: https://issues.apache.org/jira/browse/VELOCITY-657
Project: Velocity
Issue Type: Bug
Components: Engine
Affects Versions: 1.6
Reporter: Dominik Marks
Priority: Minor
Using the new "velocityHasNext" feature in loops does not work as expected.
When using the following excerpt:
#foreach ($value in $element.values)
$value
#if( $velocityHasNext )
SEPARATOR
#end
#end
and having $element.values as e.g. "test1", "test2", "test3"
I get
test1 SEPARATOR test2 SEPARATOR test3 SEPARATOR
but I would expect
test1 SEPARATOR test2 SEPARATOR test3
When looking into the source code, I see the following in
org.apache.velocity.runtime.directive.Foreach.render():
while (!maxNbrLoopsExceeded && i.hasNext())
{
// TODO: JDK 1.5+ -> Integer.valueOf()
put(context, counterName , new Integer(counter));
put(context, hasNextName, Boolean.valueOf(i.hasNext()));
Object value = i.next();
put(context, elementKey, value);
....
}
Isn't this the wrong order of instructions?
I would expect:
Object value = i.next();
put(context, hasNextName, Boolean.valueOf(i.hasNext()));
So that the $velocityHasNext variable will be filled with the "hasNext" of the
follow-up iteration and not with the "hasNext" of the current iteration (which
will always be true, otherwise the loop has finished before).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]