[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-dev
Subject:    RE: Problem with extra white spaces...
From:       "Jorge Andres Vasquez" <JVasquez () psl ! com ! co>
Date:       2004-04-16 15:57:36
Message-ID: BF3DCD5A76704C429D31668D57231B3E5F7801 () marte ! psl ! com ! co
[Download RAW message or body]

Thanks a lot Mike, it worked out perfectly.

Jorge Andrés Vásquez
Analista de Desarrollo 
PSL-Medellin


-----Mensaje original-----
De: Mike Kienenberger [mailto:mkienenb@alaska.net] 
Enviado el: Viernes, 16 de Abril de 2004 10:51 a.m.
Para: Velocity Developers List
CC: velocity-dev@jakarta.apache.org
Asunto: Re: Problem with extra white spaces...

Jorge Andres Vasquez <JVasquez@psl.com.co> 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: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic