Aneesh
Aneesh

Reputation: 151

How to do concatenation inside an EL

I just want to do something like;

<c:forEach begin="0" end="9" var="val">
  <input type="text"  value="${level${val}}">
</c:forEach>

What I want is ${level0}, ${level1}, ..., ${level9} to have some values.

The code

<input type="text" value="${level0}">

will give me the value.

That I need to show for all by using a for loop.

How can I achieve this?

Upvotes: 0

Views: 64

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280168

In servlet

Level level1 = ...; 
Level level2 = ...;
...// more levels
List<Level> levels = ...// choose your favorite implementation
levels.add(level1);
levels.add(level2);
... // add all levels in order you want
request.setAttribute("levels", levels);

Then from the jsp

<c:forEach items="levels" var="level">
    <input type="text" value="${level}">
</c:forEach>

Upvotes: 2

Related Questions