velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Will Glass-Husain <wgl...@forio.com>
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

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

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.

WILL


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 '-'>home.de/
>
> 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
wglass@forio.com
www.forio.com


---------------------------------------------------------------------
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