velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Smith <Paul.Sm...@lawlex.com.au>
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 = $MapFactory.build("{ "one"=1, "two"=2, "three"=3 }"))

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

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.

cheers,

Paul Smith

-----Original Message-----
From: Aapo Laakkonen [mailto:aapo.laakkonen@giro.fi]
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)
support:

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

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

#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 = $Global.map)
#set($map.one = 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, $Global.map)
#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:
<mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:velocity-user-help@jakarta.apache.org>

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


Mime
View raw message