Is there a way to initialize an array using velocity code without having to declare the contents of the array and without having to create a java helper method?
Equivalent in java would be: int size = 10; int[] array= new int[size]; What I want to write in velocity: // I want to set the length of $array to $size, where $size can be any number #set( $size = $JavaHelper.getSize() ) #set( $array = $size ) #foreach( $key in $array ) #end Right now the above velocity code would not work because $array is not an array, it is a scalar equal to $size. Thus, the foreach loop would never be entered. I would have to write it like this: //What I have to write in velocity (to make it work): // I want to set the length of $array to $size, where $size can be any number (in this case it is 10) #set( $size = $JavaHelper.getSize() ) //Create $array to size of $size #set( $array = ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1"...])" ) #foreach( $key in $array ) #end However the above code is static. I would have to manually enter the array contents for every possible number. I know you could create a newArray(int size) method in Java and call that from within the velocity code, but I was just wondering if there was a way to do this with purely velocity code. Thanks for the help! :) -- View this message in context: http://www.nabble.com/Initializing-Array-%28without-declaring-contents-and-without-creating-java-helper-method%29-tf3879957.html#a10995743 Sent from the Velocity - Dev mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
