Rewriting EL expressions in a loop
In my jsp page some data is read from the request object and displayed:
Code:
Dataset 1:
<br></br>
${requestScope.DataObj.person[0].name}
<br></br>
${requestScope.DataObj.person[0].age}
<br></br>
<img src="${requestScope.DataObj.person[0].image}" />
<br></br>
Dataset 2:
<br></br>
${requestScope.DataObj.person[1].name}
<br></br>
${requestScope.DataObj.person[1].age}
<br></br>
<img src="${requestScope.DataObj.person[1].image}" />
<br></br>
Is it possible to use a loop here?
Re: Rewriting EL expressions in a loop
Look at the standard tag library, specifically the forEach tag.
That'll iterate over your collection.
Re: Rewriting EL expressions in a loop
The problem are the details. I tried it this way, but it doesn't work:
Code:
<c:forEach var="x" items="${requestScope.DataObj.person}">
<c:out value="${x.name}" />
<br></br>
</c:forEach>
When I call this, I don't get any output:
Code:
<c:choose>
<c:when test="${requestScope.DataObj.person}">
<c:out value="data available: yes"></c:out>
</c:when>
<c:otherwise>
<c:out value="data available: no"></c:out>
</c:otherwise>
</c:choose>
Re: Rewriting EL expressions in a loop
hey ,
did you copy the standard tag Jar to your project?
and <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> in your page?
Re: Rewriting EL expressions in a loop
What does "it doesn't work" mean?