velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Will Glass-Husain <>
Subject Re: Putting key/value pair into hashmap from velocity template
Date Fri, 21 Jul 2006 13:10:26 GMT
Hi Matthias--

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

Use one of these two forms this instead


Second, the "put" call works fine in your example.  But since it returns 
null, it echoes back the velocity reference.   You can test this by 
doing a get after the put.

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.


Matthias Hendler wrote:
> Hello,
> I have created a simple test to show the problem I have with velocity.
> I offer my test case in a zip archive to everyone who is interested.
> Download the archive at: http://velocity.hendler<replace this and brackets by a minus
sign '-'>
> In this archive you will find the java source, all needed velocity jars, a template and
a batch file to run the test.
> Look at my template file, run the batch file and watch the output file and velocity logfile.
> I would be pleased if anyone could tell me what I am doing wrong!

Forio Business Simulations

Will Glass-Husain
phone (415) 440-7500 x89
mobile (415) 235-4293

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

View raw message