Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-velocity Wiki" 
for change notification.

The following page has been changed by Stephen Popp:
http://wiki.apache.org/jakarta-velocity/VelocityCommaIfNeeded

------------------------------------------------------------------------------
- How can you easily create a comma seperated list if items?
+ How can I easily create a comma seperated list if items?
  
- Add the global macro:
+ I first ran into this problem while using Velocity to create SQL statements.
+ The comma seperated list of Table Columns can not have a trailing comma.
  
+ To VM_global_library.vm add the '''commaIfNeeded''' macro:
+ {{{
-  *### Add a comma if needed - pass in $velocityCount for $count
+ ### Add a comma if needed - pass in $velocityCount for $count
-  *#macro('''commaIfNeeded''' $count $list)
+ #macro('''commaIfNeeded''' $count $list)
-  *#set ( $lastone = $list.Count - 1 )
+ #set ( $lastone = $list.Count - 1 )
-  *#if( $count <= $lastone ),
+ #if( $count <= $lastone ),
-  *#else
+ #else
-  *
+ 
-  *#end
+ #end
-  *#end
+ #end
+ }}}
  
  Use the '''commaIfNeeded''' Macro to create a comma seperated list:
+ {{{
+ #foreach ($column in ${Table.ColumnList})
+     p_${column.Name} IN "${Table.Name}"."${column.Name}"%Type#commaIfNeeded( 
$velocityCount  $Table.ColumnList )
+ #end
+ }}}
  
-  *#foreach ($column in ${Table.ColumnList})
-  *    p_${column.Name} IN 
"${Table.Name}"."${column.Name}"%Type#commaIfNeeded( $velocityCount  
$Table.ColumnList )
-  *#end
- 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to