You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/01/18 07:34:21 UTC

Map support in #set()

Thanks to Christoph's patch, the #set() in VTL now supports Maps.  

So you can use an object that supports the Map interface such :

#set($ref.Foo = "bar")

and Velocity will try

   ref.setFoo( "bar ")

and if that fails

   ref.put("Foo", "bar")


Issues and notes, in no real order :

1) I persoanally still am not comfortable about this, but I can't say
why.  So who cares...  I guess I want to know why this isn't supported
in the bean spec - anyone know?

2) Maybe I'm uncomfortable because it's so specific in that it supports
Map interface, which means Hashtable, HashMap, TreeMap..., rather than
introspecting for put() only, in the same way we look for get()
elsewhere.  Of course, getMethod() is something like a gazillion times
slower (really!) than instanceof, and I would guess most people use the
above provided classes, so maybe it's not that important.  And you
always have a way out using proper setter methods.

3) It was suggested we chuck Map support in both get() and put() and
stick to the bean spec. :)

Anyway, if anyone sees any problems or issues, speak now or live with it
:)

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: Map support in #set()

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"Geir Magnusson Jr." wrote:
>
> 
> 2) Maybe I'm uncomfortable because it's so specific in that it supports
> Map interface, which means Hashtable, HashMap, TreeMap..., rather than
> introspecting for put() only, in the same way we look for get()
> elsewhere.  Of course, getMethod() is something like a gazillion times
> slower (really!) than instanceof, and I would guess most people use the
> above provided classes, so maybe it's not that important.  And you
> always have a way out using proper setter methods.

I will check in tonight a version that just checks for put() if the
object doesn't implement Map, so we will then not force people to (use
objects that) implement Map while still getting the speed of instanceof
in the event they do, which will be the most common way.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity