You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Nick Bauman <ni...@cortexity.com> on 2001/05/26 04:12:36 UTC
Bug in V 1.1 rc1 (caching #if results in #foreach)
I think I found a bug in Velocity 1.1 rc 1
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.
--
Nick Bauman
Software Developer
3023 Lynn #22
Minneapolis, MN
55416
Mobile Phone: (612) 810-7406
Re: Bug in V 1.1 rc1 (caching #if results in #foreach)
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Nick Bauman wrote:
>
> Thank you, I noticed that and posted in in my bug.
>
> http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=1910
>
> It's interesting that this isn't caught as a parse error, and instead I get
> the odd output of "if(true)..."
>
> > on 5/25/01 7:12 PM, "Nick Bauman" <ni...@cortexity.com> wrote:
> >
> >> #else if
> >
> > #elseif
> >
> > Syntax is documented here:
> >
> > http://jakarta.apache.org/velocity/vtl-reference-guide.html
> >
> > -jon
>
Am I the only one who didn't get the orignal post?
It's 9:19pm EST on 5/27/01 and I haven't seen the original post.
I just checked mail-archive.com, and they didn't see it either, although
they have two responses from jon, and one from nick.
geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."
Re: Bug in V 1.1 rc1 (caching #if results in #foreach)
Posted by Jon Stevens <jo...@latchkey.com>.
on 5/27/01 12:44 PM, "Nick Bauman" <ni...@cortexity.com> wrote:
> Thank you, I noticed that and posted in in my bug.
>
> http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=1910
>
> It's interesting that this isn't caught as a parse error, and instead I get
> the odd output of "if(true)..."
It isn't a parse error because it is valid to have something like this:
#else
if the dogs come home
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>
Re: Bug in V 1.1 rc1 (caching #if results in #foreach)
Posted by Nick Bauman <ni...@cortexity.com>.
Thank you, I noticed that and posted in in my bug.
http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=1910
It's interesting that this isn't caught as a parse error, and instead I get
the odd output of "if(true)..."
> on 5/25/01 7:12 PM, "Nick Bauman" <ni...@cortexity.com> wrote:
>
>> #else if
>
> #elseif
>
> Syntax is documented here:
>
> http://jakarta.apache.org/velocity/vtl-reference-guide.html
>
> -jon
--
Nick Bauman
Software Developer
3023 Lynn #22
Minneapolis, MN
55416
Mobile Phone: (612) 810-7406
Re: Bug in V 1.1 rc1 (caching #if results in #foreach)
Posted by Jon Stevens <jo...@latchkey.com>.
on 5/25/01 7:12 PM, "Nick Bauman" <ni...@cortexity.com> wrote:
> #else if
#elseif
Syntax is documented here:
http://jakarta.apache.org/velocity/vtl-reference-guide.html
-jon