Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL: How to get array length in EL?  RSS feed

 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to use the Expression Language to get the length of an array object?
I'd like to eliminate all scriptlets from my JSP, but right now I seem to be forced to do this:
<th colspan="<%= table.getCols().length %>">
(where table is a bean whose getCols() method returns an array)
 
Charles Hasegawa
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just add a method to your bean (you said table was a bean) such as public int getNumCols() that returns the length of the the array?
Then you can replace <th colspan="<%= table.getCols().length %>">
with
<th colspan="<c ut value='${table.numCols}' />">
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would certainly work, though it seems a bit kludgy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!