1

I want to output values of a list like this, but also I want to prepend another value to only the first element of the list, i.e. valuesInRow[0]. How do I do this while also outputting the other values in the list without the prepend?

<c:forEach var="valuesInRow" items="${valuesInRows}">                                        
  <td>${idPrepend}${valuesInRow}</td>
</c:forEach>
Nikrango
  • 87
  • 2
  • 11

2 Answers2

1

You can use varStatus: How to get a index value from foreach loop in jstl

It will give you some control about the loop.

1

Maybe you could get a hold onto the current index, and use aan if to check that you are on the first one ?

<c:forEach var="valuesInRow" items="${valuesInRows}" varStatus="loop">                                        
  <td><c:if test = "${loop.index == 0}"></c:if>${idPrepend}${valuesInRow}</td>
</c:forEach>
Highbrainer
  • 750
  • 4
  • 15