Take the following JSP fragment:
<c:forEach items="${items}" varStatus="status">
${'A' + status.index}
</c:forEach>
The intent should clear, I’m trying to generate an ‘A’-based character index for each iterations through the loop. In Java, this is fine (e.g. 'A' + 1 == 'B'), but JSP EL on Tomcat 6 barfs with java.lang.NumberFormatException: For input string: "A". It seems it cannot handle characters as ordinal values.
The current solution breaks this out into a custom taglib, but this is absurd for something so trivial.
Can anyone see how to persuade EL to do this calculation?
First create the alphabet:
Then you can use fn:substring to access letters.
Your example would become:
You’ll probably need some edge case checking, but this should work.