velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <>
Subject Re: Putting key/value pair into hashmap from velocity template
Date Sat, 22 Jul 2006 08:12:55 GMT
Will Glass-Husain <> writes:

>Hi Matthias--

>Two things.  First, this syntax is not valid:
>${jMap.put("tttt123", "test")}

No. It is valid. Don't listen to Will. ;-) 

>Use one of these two forms this instead


Uhm, no?!?  ${jMap.put(...)} _is_ correct. 

If you write ${jMap}.put(), you force Velocity to evaluate ${jMap}
without looking at the surrounding template code. This leads to
executing jMap.toString() which renders the map as text and then
adding .put(...) after it.

>The reason Velocity works this way is that templates are typically used 
>to just display data.  They very rarely change internal state.  (makes 
>for less error-prone programming).  If you want to call "put" from 
>within your template and not have it return null, you'll need to write a 
>Map wrapper which is either defined void or returns an actual value.

... or use the quiet notation $! or use 1.5-dev where you can set a property to
have "null" as a valid reference. 

	Best regards

Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH        +49 9131 50 654 0

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

Social behaviour: Bavarians can be extremely egalitarian and folksy.
Most Franconians do not like to be called Bavarians.

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

View raw message