This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree
Skip to end of metadata
Go to start of metadata

How can I easily create a comma separated list if items?

I first ran into this problem while using Velocity to create SQL statements. The comma separated list of Table Columns can not have a trailing comma.

To VM_global_library.vm add the commaIfNeeded macro:

##-----------------------------------------------------------------
## Add commas in a comma separated list to all items but the last
## Param: $index - pass in $velocityCount
## Param: $list  - pass in your velocity list variable
##-----------------------------------------------------------------
#macro(commaIfNeeded $index $list)
#set ( $lastone = $list.Count - 1 )
#if( $index <= $lastone ),
#else

#end
#end

Use the commaIfNeeded Macro to create a comma separated list:

#foreach ($column in ${Table.ColumnList})
    p_${column.Name} IN "${Table.Name}"."${column.Name}"%Type#commaIfNeeded( $velocityCount  $Table.ColumnList )
#end
  • No labels