velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Romianowski" <megap...@gmx.de>
Subject RE: String to Int for array index
Date Thu, 12 Dec 2002 16:47:31 GMT
According to the "String to int"-Thread we had lately, you could
use the Math-Tool (http://jakarta.apache.org/velocity/toolsubproject.html)

or as a quick and dirty hack

#set ($int = 1)
#set ($converted = $int.parseInt("2"))

I'd recommend the MathTool :)

Peter

> -----Original Message-----
> From: Jason Leidigh [mailto:jleidigh@uol.com.ar] 
> Sent: Thursday, December 12, 2002 5:48 PM
> To: Velocity Users List
> Subject: String to Int for array index
> 
> 
> 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