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 Thu, 20 Jul 2006 17:58:21 GMT
"Matthias Hendler" <> writes:


>thanx for the many answers.
>What I forgot to mention is that I use Velocity 1.4.

Ok. I tried with that version.

>I have tested a lot with my code before.

>My java code looks like this:
>final VelocityEngine ve = new VelocityEngine();
>final VelocityContext context;
>context = new VelocityContext();

>context.put("myMap", new HashMap());
>context.put("myList", new ArrayList());
>context.put("myTable", new Hashtable());

>// Velocity
>final boolean success = ve.evaluate(context, writerVelocity, "Velocity", readerEscaped);

>My template looks like this:
>1. $myMap.toString()
>2. $myMap.getClass()
>3. $myMap.isEmpty()
>4. ${myMap.put("tttt123", "test")}

Ok. I tried that code and while I have to say that, it works fine for me.

>Ouput of the template IF line 4 is "deleted".
>1. {}
>2. class java.util.HashMap
>3. true

Just write $!{myMap... and it won't bother you anyway. :-)

>If line 4 is part of the template I sill get the invalid reference exception.

Hm. Maybe I'm getting something wrong. Where do you get this exception? On
screen / in the template? In a log file? I can't reproduce it but I'd love
to. Do you load any From your code I'd say not.

>So, I did some testing around my problem.
>1. $myList.set(0, "Hallo")
>This works.

Sure. java.util.List::set(int index, Object element)

>2. ${myMap.put("tttt123", "test")}

Works fine for me.

>3. $myTable.put("test", "hallo")

Works fine for me, too. 

>Any ideas why it works in case 1 and not in case 2 and 3?

I'd like to see the exception. Can you send it to me (either through the list
or directly).

	Best regards


>Echte DSL-Flatrate dauerhaft für 0,- Euro*!
>"Feel free" mit GMX DSL!

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

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