velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: Re: Putting key/value pair into hashmap from velocity template
Date Thu, 20 Jul 2006 16:46:47 GMT
see inline

On 7/20/06, Matthias Hendler <hendler2@gmx.de> wrote:
> Hello,
>
> thanx for the many answers.
> What I forgot to mention is that I use Velocity 1.4.

can we assume you're using the default properties?  they shouldn't
matter for this unless you're using a custom uberspector or something,
but we might as well get what info we can.

>
> 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")}
>
> Ouput of the template IF line 4 is "deleted".
> 1. {}
> 2. class java.util.HashMap
> 3. true

what's the output if it's not deleted?

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

invalid reference exception, eh?  try this:

4. $myMap.put("tttt123", "test")
5. $myMap.get("tttt123")
6. $!myMap.put("foo", "bar")
7. $myMap.get("foo")

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