Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access JSTL tag from code inside of forEach loop

Tags:

java

jsp

jstl

Is it possible to access JSTL's forEach variable via code from within the loop?

<c:forEach items="${elements}" var="element">
    <% element.someMethod(); %>
</c:forEach>
like image 343
Steve Kuo Avatar asked Nov 06 '22 22:11

Steve Kuo


1 Answers

Well, I believe "element" is stored in the page context.

<c:forEach items="${elements}" var="element">
    <% ((Element) pageContext.getAttribute("elements")).someMethod(); %>
</c:forEach>
like image 127
sblundy Avatar answered Nov 11 '22 07:11

sblundy