You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Beland, Andre" <An...@nrc-cnrc.gc.ca> on 2007/08/20 23:10:36 UTC

Possible to define a literal Map in a template?

The user documentation sais:
#set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map 


But I get a parsing exception when I try:
------------------------------------------------------------------------
--------
##Set some values within the template
## Works fine
#set( $text = "this is some text" )

## Map - BROKEN
#set( $myLiteralMap = {"message" : "hello", "foo" : "bar"}) 

Here is some text:
$text

Here are some values:
#foreach( $key in $myLiteralMap.keySet() )
  $key  has a value of:  $myLiteralMap.get($key)
#end
------------------------------------------------------------------------
--------


Is it possible to INITIALIZE a map from within a template? If so, how?

Thanks.



Re: Possible to define a literal Map in a template?

Posted by Claude Brisson <cl...@renegat.net>.
Maps are available in Velocity 1.5. Are you still using 1.4?

Also, if you write #set($monkey.Map=...) the $monkey object must have a
setMap method or a generic setter.


 Claude

Le lundi 20 août 2007 à 17:10 -0400, Beland, Andre a écrit :
> The user documentation sais:
> #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map 
> 
> 
> But I get a parsing exception when I try:
> ------------------------------------------------------------------------
> --------
> ##Set some values within the template
> ## Works fine
> #set( $text = "this is some text" )
> 
> ## Map - BROKEN
> #set( $myLiteralMap = {"message" : "hello", "foo" : "bar"}) 
> 
> Here is some text:
> $text
> 
> Here are some values:
> #foreach( $key in $myLiteralMap.keySet() )
>   $key  has a value of:  $myLiteralMap.get($key)
> #end
> ------------------------------------------------------------------------
> --------
> 
> 
> Is it possible to INITIALIZE a map from within a template? If so, how?
> 
> Thanks.
> 
> 


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