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
We can also convert int to char in Java by adding the character '0' to the integer data type. This converts the number into its ASCII value, which after typecasting gives the required character.
An expression language makes it possible to easily access application data stored in JavaBeans components. For example, the JSP expression language allows a page author to access a bean using simple syntax such as ${name} for a simple variable or ${name. foo. bar} for a nested property.
For example, to access a parameter named order, use the expression ${param. order} or ${param["order"]}. The param object returns single string values, whereas the paramValues object returns string arrays.
1.1 Syntax of Expression Language (EL) To enable the EL expression in a JSP, developers need to use following page directive. To get a better idea, on how expression works in a JSP, we will see the below example where EL is used as an operator to add two numbers and get the output.
That's not possible. Your best bet is to display it as XML entity.
<c:forEach items="${list}" var="item" varStatus="loop">
<sup>&#${loop.index + 97};</sup> ${item}<br />
</c:forEach>
It'll end up like as
<sup>a</sup> item1<br />
<sup>b</sup> item2<br />
<sup>c</sup> item3<br />
...
The a
represents an a
and so on.
a item1
b item2
c item3
...
You've only a problem when the list is over 26 items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With