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:

  [EMAIL PROTECTED]@parseInt(matrixIndex)].length}

 

 

Jim

Reply via email to