You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Henning Schmiedehausen (JIRA)" <de...@velocity.apache.org> on 2007/03/08 01:18:27 UTC

[jira] Closed: (VELOCITY-6) #if in #foreach seems to be caching results in Velocity 1.1 rc1

     [ https://issues.apache.org/jira/browse/VELOCITY-6?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henning Schmiedehausen closed VELOCITY-6.
-----------------------------------------


> #if in #foreach seems to be caching results in Velocity 1.1 rc1
> ---------------------------------------------------------------
>
>                 Key: VELOCITY-6
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-6
>             Project: Velocity
>          Issue Type: Bug
>          Components: Build
>    Affects Versions: 1.0b3
>         Environment: Operating System: Linux
> Platform: PC
>            Reporter: Nick Bauman
>         Assigned To: Velocity-Dev List
>
> Using this code:
> ---8<---
> import java.io.*;
> import java.util.*;
> import org.apache.velocity.VelocityContext;
> import org.apache.velocity.Template;
> import org.apache.velocity.exception.*;
> import org.apache.velocity.app.Velocity;
> public class VelTest {
>   public static void main(String[] args) {
>     Template template = null;
>     try {
>       Properties props = new Properties();
>       props.setProperty("file.resource.loader.path", args[0]);
>       Velocity.init(props);
>       VelocityContext context = new VelocityContext();
>       HashMap map = new HashMap();
>       map.put("wonka", "werfl");
>       map.put("wertheimer", "wiffen");
>       map.put("wicken", "witch");
>       map.put("wooble", new Integer(3767));
>       map.put("wablle", new Long(System.currentTimeMillis()));
>       context.put("name", map);
>       context.put("nameKeys", map.keySet());
>       template = Velocity.getTemplate(args[1]);
>       StringWriter sw = new StringWriter();
>       template.merge(context, sw);
>       System.out.println("template output: "+sw);
>     } catch(ResourceNotFoundException rnfe) {
>       System.out.println("Can't find your template!");
>     } catch(ParseErrorException pee) {
>       System.out.println("Your template has a syntax error: "+pee);
>     } catch(Exception e) {
>       System.out.println("Something bad happened: "+e);
>     }
>   }
> }
> ---8<---
> And using this template:
> ---8<---
> <HTML>
> <BODY>
> Hello. This is about the object \$name whose value is $name
> \$name is actually a $name.getClass().getName()
> Name is $name.size() in size
> <ul>
> #foreach ($element in $nameKeys)
>   <li>key=$element value=$name.get($element)</li>
> #if ($name.get($element).getClass().getName().equals("java.lang.String"))
>     The value is a String type
>   #else if
> ($name.get($element).getClass().getName().equals("java.lang.Integer"))
>     The value is an Integer type
>   #end
> #end
> </ul>
> </BODY>
> </HTML>
> ---8<---
> I get this output:
> ---8<---
> <HTML>
> <BODY>
> Hello. This is about the object $name whose value is {wicken=witch,
> wonka=werfl, wooble=3767, wablle=990844112188, wertheimer=wiffen}
> $name is actually a java.util.HashMap 
> Name is 5 in size
> <ul>
> <li>key=wicken value=witch</li>
> The value is a String type
>     <li>key=wonka value=werfl</li>
> The value is a String type
>     <li>key=wooble value=3767</li>
> if (true)
>     The value is an Integer type
>     <li>key=wablle value=990844112188</li>
> if (false)
>     The value is an Integer type
>     <li>key=wertheimer value=wiffen</li>
> The value is a String type
>   </ul>
> </BODY>
> </HTML>
> ---8<---
> Notice the weird "if(false)" diddly-doos in there.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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