1

When I try to access wrap.myUtilDate I get an error:

`wrap.myUtilDate` cannot be resolved to a type

Can c:forEach loop values be accessed from a scriptlet?

<c:forEach items="${myWraps}" var="wrap" varStatus="status">

    <%

    java.util.Date myUtilDate = wrap.myUtilDate;
    org.joda.time.DateTime myJodaDate = new org.joda.time.DateTime(myUtilDate);

    %>

    <td><joda:format value="${myJodaDate}" style="LL"/></td>

</c:forEach>
Greeley
  • 11
  • 1
  • 2

2 Answers2

3

I think JSTL keeps the variables in either page or pageContext implicit objects. Just try both of them to be sure.

java.util.Date myUtilDate = ((MyWrap) pageContext.getAttribute("wrap")).myUtilDate;
adarshr
  • 61,315
  • 23
  • 138
  • 167
-2

If u get myWraps from the request, make like this

  <c:forEach items="${requestScope.myWraps}" var="wrap" varStatus="status">

<%

java.util.Date myUtilDate = wrap.myUtilDate;
org.joda.time.DateTime myJodaDate = new org.joda.time.DateTime(myUtilDate);

%>

<td><joda:format value="${myJodaDate}" style="LL"/></td>

palAlaa
  • 9,500
  • 33
  • 107
  • 166
  • I don't think this code will work if you don't add pageContext.setAttribute("myJodaDate", myJodaDate); before closing the scriptlet – Mav3656 Jun 28 '23 at 10:39