velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Smith <>
Subject RE: Map support in VTL
Date Wed, 09 Oct 2002 22:50:08 GMT
You know, you could write a Java factory object that parses the text and
returns a Map, and just
drop that Java object into the context?

#set( $myMap = $"{ "one"=1, "two"=2, "three"=3 }"))

I know that's not quite as good as built in support, but it could easily be

I don't think I've seen any language (scripting or otherwise) that supports
that Map construct, but I am probably going to have to eat my hat as soon as
I say that.

I think the reason behind the lack is that the syntax can be a little too
hard to read for large Maps, and so they never bothered.


Paul Smith

-----Original Message-----
From: Aapo Laakkonen []
Sent: Thursday, 10 October 2002 8:41 AM
To: 'Velocity Users List'
Subject: Map support in VTL

Is it possibly to add map (java.util.Map) support to VTL. What I mean is
something similar as the current Collection (java.util.ArrayList)

#set($list = [ "one", "two", "three" ])

What I would like to see is Map (java.util.HashMap) support like the

#set($map = { "one"=1, "two"=2, "three"=3 })

Is this too much asked? I'm not sure about the syntax above, but
something similar. Currently I have to do something like this to
archieve the same results:

#set($map = $
#set($ = 1)
#set($map.two = 2)
#set($map.three = 3)

It's fine, but not as compact as I would like it to be. Look for example
the following:

#set($list = [ { "firstname"="Aapo", "lastname"="laakkonen" }, "text" ]

Seems simple, but this is what I have to do right now:

#set($list = []) ## or #set($list = $Global.list) 

$list.add(0, $
#set($map = $list.get(0))

#set($map.firstname = "Aapo")
#set($map.lastname = "Laakkonen")

$list.add(1, "text")

As you see in this simple example, this second approach requires much
more typing.

Kind Regards
Aapo Laakkonen

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message