You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ron Piterman <rp...@gmx.net> on 2006/12/15 17:32:42 UTC

Re: Array-gotcha in .script files

Would you place this in the wiki?
Cheers,
Ron


Jim Steinberger wrote:
> Just wanted to give a heads up on a gotcha I ran into.
> 
>  
> 
> The "index" value of the "foreach" tag is stored as a String, not an
> integer, so be careful when using it to, say, index into an array.
> 
>  
> 
> e.g. If you have a two-dimensional array stored in the input-symbol
> "matrix", the following will work fine:
> 
>   ${matrix[0].length}
> 
>  
> 
> But the following, where "matrixIndex" is the symbol used for a
> surrounding "foreach"-tag's "index" value, will throw an error:
> 
>   ${matrix[matrixIndex].length}
> 
>  
> 
> The error will tell you that "matrix" does not have the property: 0.
> i.e. since matrixIndex is a String, it's looking for a property of the
> array-object named "0".
> 
>  
> 
> This issue hadn't hit me before because OGNL casts it automatically when
> used in expressions like: "${matrixIndex > 0}".  But since a
> String-input is valid as a [] parameter in OGNL, it doesn't know to cast
> it.
> 
>  
> 
>  
> 
> I used the workaround:
> 
>   ${matrix[@java.lang.Integer@parseInt(matrixIndex)].length}
> 
>  
> 
>  
> 
> Jim
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org