You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jorge Andres Vasquez <JV...@psl.com.co> on 2004/04/16 17:22:15 UTC
Problem with extra white spaces...
Greetings to everybody,
I am new to Velocity and currently I´m using it to create a javascript file, which is the configuration for a dynamic menu.
The specific part of my script that is not printing fine is:
...
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....
Thanks to everyone for your time to read this.
Jorge Andrés Vásquez
Analista de Desarrollo
PSL-Medellin
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: Problem with extra white spaces...
Posted by Mike Kienenberger <mk...@alaska.net>.
Jorge Andres Vasquez <JV...@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