You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Dominik Marks (JIRA)" <de...@velocity.apache.org> on 2008/12/23 14:19:44 UTC

[jira] Created: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

$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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Michael Parmeley (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Parmeley updated VELOCITY-657:
--------------------------------------

    Comment: was deleted

(was: I am using velocity 1.6.2 and this is still occuring. Using $velocityHasNext does not work in nested loops.

For example:

I have: #foreach(${column} in ${columns})${column.columnName}#if(${velocityHasNext}),#end#end

However, if I have two columns named "foo" and "bar" this is resulting in "foobar". If I change the condition in the if statment to something cheesy like (3 > 2) then the expected results of "foo,bar" is generated.

So the $velocityHasNext is still not working in velocity 1.6.2.

I have this property in my velocity.properties:

directive.foreach.iterator.name = velocityHasNext
)

> $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
>             Fix For: 1.6.2, 1.7
>
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Jarkko Viinamäki (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12659646#action_12659646 ] 

Jarkko Viinamäki commented on VELOCITY-657:
-------------------------------------------

Since this has been fixed in the trunk I think we can mark this as resolved.

> $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
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-657.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.7
                   1.6.2

> $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
>             Fix For: 1.6.2, 1.7
>
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Byron Foster (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12658987#action_12658987 ] 

Byron Foster commented on VELOCITY-657:
---------------------------------------

Thanks for the test case.  Looks like a candidate for 1.6.2



> $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
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Jarkko Viinamäki (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jarkko Viinamäki updated VELOCITY-657:
--------------------------------------

    Attachment: velocity-657-testcase.patch

> $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
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12659121#action_12659121 ] 

Nathan Bubna commented on VELOCITY-657:
---------------------------------------

Yeah, we need to merge the change to the 1.6.x branch.  Perhaps then someone else will be willing to try and run the 1.6.2 release process?  Claude is right that i should not be the only one prepared to do releases.

> $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
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Michael Parmeley (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12777514#action_12777514 ] 

Michael Parmeley commented on VELOCITY-657:
-------------------------------------------

I am using velocity 1.6.2 and this is still occuring. Using $velocityHasNext does not work in nested loops.

For example:

I have: #foreach(${column} in ${columns})${column.columnName}#if(${velocityHasNext}),#end#end

However, if I have two columns named "foo" and "bar" this is resulting in "foobar". If I change the condition in the if statment to something cheesy like (3 > 2) then the expected results of "foo,bar" is generated.

So the $velocityHasNext is still not working in velocity 1.6.2.

I have this property in my velocity.properties:

directive.foreach.iterator.name = velocityHasNext


> $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
>             Fix For: 1.6.2, 1.7
>
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-657) $velocityHasNext not working properly (returns true even if iterator does not have next value)

Posted by "Jarkko Viinamäki (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12658973#action_12658973 ] 

Jarkko Viinamäki commented on VELOCITY-657:
-------------------------------------------

It seems that this has been fixed in the trunk (on Dec-14) but the 1.6.1 release contains this bug. There should always be JUnit tests for new features...

> $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
>         Attachments: velocity-657-testcase.patch
>
>
> 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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org