velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Range operator
Date Wed, 07 Mar 2001 13:33:29 GMT
"???(Brian Lee)" wrote:
> 
> I set value of $var in doBuildTemplate() method of Index.java source like this.
> 
> context.put("var", String.valueOf(10));
> 
> $var is substituted well outside the #foreach loop,
> but it's not in #foreach statement.

That won't work.  We don't do type casts from strings :)

do 

context.put("var", new Integer(10) );

geir

> 
> -----Original Message-----
> From: gmj@mta6.srv.hcvlny.cv.net [mailto:gmj@mta6.srv.hcvlny.cv.net]On Behalf Of Geir
Magnusson Jr.
> Sent: Wednesday, March 07, 2001 8:24 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: Range operator
> 
> À⵿̱ wrote:
> 
> > I have a question about range operator.
> > This code is working
> >
> >     #foreach ($i in [1..10])
> >       $i
> >     #end
> >
> > But, that code is not working
> >
> >     #foreach ($i in [1..$var])
> >       $i
> >     #end
> >
> > and I set $var to 10.
> 
> The following example works :
> 
> #set($var = 10)
> 
> #foreach($i in [1..$var])
> $i
> #end
> 
> (I just tried it :)
> 
> Take a look at your template again to make sure that all is well - if
> you still have a problem, send us your tempalate so we can take a look.
> 
> geir
> 
> --
> Geir Magnusson Jr.                               geirm@optonline.com
> Developing for the web?  See http://jakarta.apache.org/velocity/

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Developing for the web?  See http://jakarta.apache.org/velocity/

Mime
View raw message