velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <...@intermeta.de>
Subject Re: Putting key/value pair into hashmap from velocity template
Date Sat, 22 Jul 2006 08:12:55 GMT
Will Glass-Husain <wglass@forio.com> 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

>$jMap.put("ttt123","test")
>${jMap}.put("ttt123","test")

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
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

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.
                                    -- http://en.wikipedia.org/wiki/Bavaria
Most Franconians do not like to be called Bavarians.
                                    -- http://en.wikipedia.org/wiki/Franconia

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


Mime
View raw message