You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by 이기동 <br...@3rsoft.com> on 2001/03/07 08:19:29 UTC
Range operator
Hi,
I'm new to velocity.
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.
How do I work this code?
Thanks in advance.
Re: Range operator
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"???(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/
RE: Range operator
Posted by "???(Brian Lee)" <br...@3rsoft.com>.
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.
-----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/
Re: Range operator
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
À⵿̱ 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/