You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Byron Foster (JIRA)" <de...@velocity.apache.org> on 2009/02/15 16:14:59 UTC
[jira] Created: (VELOCITY-696) Add index parameter to #foreach
directive to define an index variable
Add index parameter to #foreach directive to define an index variable
---------------------------------------------------------------------
Key: VELOCITY-696
URL: https://issues.apache.org/jira/browse/VELOCITY-696
Project: Velocity
Issue Type: Improvement
Components: Engine
Affects Versions: 2.0
Reporter: Byron Foster
Allow the following:
#foreach($user in $users index $i)
#end
So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Byron Foster (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674784#action_12674784 ]
Byron Foster commented on VELOCITY-696:
---------------------------------------
Syntax styles are difficult because everyone has an opinion on what looks good, but I think for the reasons given by Claude in VELOCITY-680 it looks cluttered to me. Also, given the way directives are parsed I speculate that it may be difficult to get the parser to cooperate.
I don't think #for is that much of a user option beyond any custom plugin a user writes for Velocity. I didn't intent for anything in the contrib directory to be available to user's out of the box, or be officially mentioned.
<digress>
The whole custom directive thing is actually very powerful, and under utilized me thinks. 2.0 may be well served to formalize the API a little, and maybe add a discussion in the developer guide.
</digress>
Anyway, I have no issue with implementing a 'hasNext' keyword. I even considered throwing it in for completeness. so yes, both #foreach($a in $b hasNext $n) and #foreach($a in $b index $i hasNext $n) would work.
I wouldn't cry over removing $velocityHasNext or $velocityCount :), but I wonder about maybe a little backward compatibility. Official support and documentation could be dropped in 2.0, and state a warning that they'll be completely removed in future releases. I don't know, I could go either way.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Byron Foster (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674256#action_12674256 ]
Byron Foster commented on VELOCITY-696:
---------------------------------------
When the 'index' keyword is specified the variable defined overrides the name specified by 'directive.foreach.counter.name', and numbering begins with 0.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674721#action_12674721 ]
Nathan Bubna commented on VELOCITY-696:
---------------------------------------
New thought. How does this syntax look:
#foreach[index $i]( $user in $users )...#end
#foreach[index $i, hasNext $next]( $user in $users ) ... #end
Think of it as a separation between the main function of the directive and the "configuration" of the directive.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Byron Foster (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12687992#action_12687992 ]
Byron Foster commented on VELOCITY-696:
---------------------------------------
Yea, I should have closed this issue with a "Will not Fix".
No, this behavior will not be added to #foreach, The direction is VELOCITY-704.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674719#action_12674719 ]
Nathan Bubna commented on VELOCITY-696:
---------------------------------------
Ok, we've established that i think this is ugly syntactically. :) I haven't decided to veto it yet, though i have other complaints. One is that it feels incomplete; what about $velocityHasNext? Are you willing/able to push it to also support #foreach( $user in $users hasNext $hN ) and #foreach( $user in $users index $i hasNext $hN )? The other is that we (or i, at least) already support another ugly (but more extensible) solution that handles both the index and hasNext cases: LoopTool. Moving this functionality to an optional #for directive doesn't feel like a good solution either. Having a two ways to skin a cat is not simpler than having one way. Again, it's more to learn and more to decide. Currently a 2.0 user can handle an index-sensitive #foreach via:
#foreach and the default $velocityCount
#foreach and a configured $indexref
#foreach and LoopTool
#for and a specified index var
#for and the default $velocityCount
#for and a configured $indexref
#for and a specified index $indexref
#for and LoopTool
That's without even mentioning $velocityHasNext and the index start value. Not simple, not good. I think, if we want to support specifying the index variable in the #foreach args, then we should just do it in #foreach, not an optional directive. It should also support hasNext to be consistent. And, we should remove the ability to configure the default names (velocityCount and velocityHasNext), as that would no longer be necessary. Either that, or we leave the configuration options, don't add the argument syntax and encourage people to use LoopTool if they need more advanced stuff. Either way, we keep the list above to just three options and no limitations.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Stefan Endrullis (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12685392#action_12685392 ]
Stefan Endrullis commented on VELOCITY-696:
-------------------------------------------
I'm a bit confused about the resolution of this issue. It's marked as "fixed", but what does that mean? It's available in contrib, but it's not going to be a feature of the official #foreach, is it?
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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] Issue Comment Edited: (VELOCITY-696) Add index parameter to
#foreach directive to define an index variable
Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674721#action_12674721 ]
nbubna edited comment on VELOCITY-696 at 2/18/09 10:28 AM:
-----------------------------------------------------------------
New thought. How does this syntax look:
#foreach( $user in $users ) $user #end
#foreach[index $i]( $user in $users ) $user $i #end
#foreach[index $i, hasNext $next]( $user in $users ) $user $i $next #end
Think of it as a separation between the main function of the directive and the "configuration" of the directive.
was (Author: nbubna):
New thought. How does this syntax look:
#foreach[index $i]( $user in $users )...#end
#foreach[index $i, hasNext $next]( $user in $users ) ... #end
Think of it as a separation between the main function of the directive and the "configuration" of the directive.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Byron Foster (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Byron Foster resolved VELOCITY-696.
-----------------------------------
Resolution: Fixed
I've moved this functionality into a custom directive called #for which can be accessed from the directive.contrib directory using the velocity property
userdirective = org.apache.velocity.runtime.directive.contrib.For
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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-696) Add index parameter to #foreach
directive to define an index variable
Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
[ https://issues.apache.org/jira/browse/VELOCITY-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674797#action_12674797 ]
Nathan Bubna commented on VELOCITY-696:
---------------------------------------
Yeah, Claude has completely detached me from the bracket syntax with the control object idea.
As for #for, i suppose i can't complain about it complexifying things if the contrib stuff remains undocumented and unsupported.
> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
> Key: VELOCITY-696
> URL: https://issues.apache.org/jira/browse/VELOCITY-696
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 2.0
> Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration. This is similar in functionality to the implicitly defined index variable, except this is more explicit.
--
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