velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matías Giovannini <mat...@k-bell.com>
Subject Re: String to Int for array index
Date Thu, 12 Dec 2002 16:51:05 GMT
If you're using the VelocityViewServlet in the velocity-tools 
subproject, include the MathTool.

Then, you can use

$math.toInteger("10")

(assuming you've configured your toolbox so that MathTool gets bound to 
the "math" reference).

HTH,
Matías.

On Thursday, December 12, 2002, at 01:48 PM, Jason Leidigh wrote:

> I have a var I pass in a hidden field from one vm to the next.  The 
> var, which is a number is being intepreted by velocity as a string but 
> I want to use it to index a local array?  Ex:
>
> page1.vm
>
> <html>... yada yada
> #set ($arr = ["One", "Two"])
> #set ($x = 1)
> $arr.get($x) #* Works and prints "One" *#
> <input type="hidden" name="val" value="$x">
> </html>
>
> page2.vm
>
> <html>
> #set ($arr = ["One", "Two"])
> $myBean.val  #*  Prints "1" *#
>
> $arr.get( $myBean.val ) #* FAILS, Prints: "$arr.get( $myBean.val )" *#
>
> I know the simple answer is  make sure the  bean/servlet does the 
> conversion internally but I am dealing with a closed solution which 
> passes me form vars from one page to the next and I have no control 
> until I get to the next vm.  I think maybe a tool is my only way to 
> go......can anyone help?
>
> Thanks
> Jason Leidigh
>
>
>
> --
> To unsubscribe, e-mail:   
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:velocity-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message