I need to display incremented single characters to denote footnotes in a table of data in a JSP. In Java I would normally have a char variable and just increment it, or convert an int to a char by casting it (e.g. (char)(i + 97) to convert a 0-based index to a-z). I can't figure out how to do this in expression language short of writing my own JSTL function.
Does anyone know how to convert an int to char in EL? Or how to increment a char variable in EL? Or possibly even a better technique to do what I'm trying to do in JSP/EL?
Example of what I need to be able to produce:
a mydata
b myotherdata
...
a first footnote
b second footnote
You can use c:set and xml entity tags to cast the integer to a character. You'll have to use the backslash in order to escape the # or, the id variable will be set to literally
&#{(i.index+97)}
rather than evaluating the${...}
codeThe following example will loop through the "list" variables and output a div for each one with the id and contents starting at "a".
This would output the following, assuming there are 5 elements in the "list" collection.
As noted in the other answer, this will only work if your list size is under 27.
That's not possible. Your best bet is to display it as XML entity.
It'll end up like as
The
a
represents ana
and so on.You've only a problem when the list is over 26 items.