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

>Hello,

>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();

>// TODO MHE
>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 velocity.properties? From your code I'd say not.


>So, I did some testing around my problem.
>Conclusion:
>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.

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













































>-- 


>Echte DSL-Flatrate dauerhaft für 0,- Euro*!
>"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

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

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