Thanks a lot Mike, it worked out perfectly.

Jorge Andr�s V�squez
Analista de Desarrollo 
PSL-Medellin


-----Mensaje original-----
De: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
Enviado el: Viernes, 16 de Abril de 2004 10:51 a.m.
Para: Velocity Developers List
CC: [EMAIL PROTECTED]
Asunto: Re: Problem with extra white spaces...

Jorge Andres Vasquez <[EMAIL PROTECTED]> wrote:
> Menu$counterL1=new 
Array("$pull.getDisplay()","$pull.url","",#countChildren($pull.getItemList() 
$counter)$counter,#firstLevelHeight($menu.barMenu 
$height)$height,#firstLevelWidth($pull 
$width)$width,"","","","","","",-1,-1,-1,"","");
> ...
> This fragment of code calls the macro:
> 
> #macro ( countChildren $allOptions $counter )
>       #set( $counter=0 )
>       #foreach($item in $allOptions)
>               #if($permissions.contains($item.getSecurityId()))
>                       #set( $counter=$counter+1 )
>               #end
>       #end
> #end
> 
> .....
> 
> and is generating the output:
> 
> Menu2=new Array("File","/file.jsp","",                                               
>                                          
2,5,80,"","","","","","",-1,-1,-1,"","");
> 
> With a couple of extra spaces in the fourth element of the array (just 
before the 2) which is where the macro gets called.
> 
> My question is how can I modify the macro to prevent extra blank spaces 
from appearing in the output generation....


First off, this is really a velocity-user question.

Second, if you get rid of the spaces in your macro, you won't see them in 
your output.
I realize that this makes the macro harder to understand, but that's how 
velocity works since some velocity-generated files are white-space 
sensitive.

For example,

#macro ( countChildren $allOptions $counter )
#set    ( $counter=0 )
#foreach        ($item in $allOptions)
#if                             ($permissions.contains($item.getSecurityId()))
#set            ( $counter=$counter+1 )
#end##                  if $permissions
#end##          foreach $item
#end##  macro countChildren

or to be absolutely certain trail every directive with ##.


#macro ( countChildren $allOptions $counter )##
#set    ( $counter=0 )##
#foreach        ($item in $allOptions)##
#if                             ($permissions.contains($item.getSecurityId()))##
#set            ( $counter=$counter+1 )##
#end##
#end##
#end##

Alternately, you can be certain it works (and is completely unreadable) by 
doing

#macro ( countChildren $allOptions $counter )#set( $counter=0 
)#foreach($item in 
$allOptions)#if($permissions.contains($item.getSecurityId()))#set( 
$counter=$counter+1 )#end#end#end##


Generally, any whitespace you put before a directive will end up in your 
output.  Whitespace after a directive may or may not appear.

-Mike


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


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

Reply via email to