You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Steve O'Hara <so...@pivotal-solutions.co.uk> on 2004/11/15 23:22:46 UTC
Referencing arrays
I'm trying to reference a 2 dimensional array of strings using the following
:-
#if ($Results)
<table width="100%" border="0" cellpadding="2" cellspacing="0">
#foreach ($Label in $Labels)
<tr>
<td valign="top">$!Label </a></td>
<td valign="top">$Results[0][$velocityCount]</td>
</tr>
#end
</table>
#end
Unfortunately I just get [[Ljava.lang.String;@1684e26[0][x] where x is the
$velocityCount.
Anyone know how to get this to work?
Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Referencing arrays
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Steve,
> I'm trying to reference a 2 dimensional array of strings using the following
> :-
>
> #if ($Results)
> <table width="100%" border="0" cellpadding="2" cellspacing="0">
> #foreach ($Label in $Labels)
> <tr>
> <td valign="top">$!Label </a></td>
> <td valign="top">$Results[0][$velocityCount]</td>
> </tr>
> #end
> </table>
> #end
>
> Unfortunately I just get [[Ljava.lang.String;@1684e26[0][x] where x is the
> $velocityCount.
>
> Anyone know how to get this to work?
AOTM, you can't.
What you _can_ do is:
1. Put the Label and Result in a JavaBean and iterate through an
array/List of that.
2. Use ArrayTool. :)
http://wiki.apache.org/jakarta-velocity/ArrayTool
I prefer #1.
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Referencing arrays
Posted by Mike Kienenberger <mk...@alaska.net>.
Steve O'Hara <so...@pivotal-solutions.co.uk> wrote:
> I'm trying to reference a 2 dimensional array of strings using the
following
> <td valign="top">$Results[0][$velocityCount]</td>
> Unfortunately I just get [[Ljava.lang.String;@1684e26[0][x] where x is the
> $velocityCount.
Array notation is not part of the Velocity Template Language.
You can download Shinobu Kawai's ArrayTool to add support for arrays, or you
can create your own custom tool.
http://wiki.apache.org/jakarta-velocity/ArrayTool
I played around with ArrayTool earlier today, and it seems to work fine.
$array.get($array.get($Results, 0), $velocityCount)
-Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org