Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert int to char in JSP expression language?

Tags:

char

int

jsp

el

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

like image 674
james.bunt Avatar asked Jan 07 '11 01:01

james.bunt


People also ask

How do I convert an int to a char?

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.

What is expression language in JSP?

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.

What are the uses of JSP expression explain with example?

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.

Which of the following will enable expression language in JSP?

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.


1 Answers

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>&#97;</sup> item1<br />
<sup>&#98;</sup> item2<br />
<sup>&#99;</sup> item3<br />
...

The &#x61; represents an a and so on.

a item1
b item2
c item3
...

You've only a problem when the list is over 26 items.

like image 98
BalusC Avatar answered Sep 20 '22 05:09

BalusC