1

I'm a bit confused. I'd like to know if there's a way to initialize an Array in javascript inside a c:forEach tag.

var Array = [];
   <c:forEach var="item" items="${data}">
       // something like -> Array[i] = ${item.user.fullName}
   </c:forEach>

${data} is passed to the .tag page through this command at the beginning:

<jsp:directive.attribute name="data" required="true" rtexprvalue="true" type="java.util.Collection" />

I know that something is working cause I see few fullName sometimes.

I don't know exactly if this is possible. I'm on this project and I'm trying to solve this.

Thanks.

  • 1
    Why don't you just generate the array of full names on the java side and then pass that? That's usually a lot better than doing it in the javascript – Sacha Jun 07 '18 at 13:54

1 Answers1

0

I solved it! This is the code:

var Array = [];
      <c:forEach var="item" items="${data}" varStatus="yourStatus">
        Array[${yourStatus.index}] = '${item.user.fullName}';
      </c:forEach>

I found a perfect solution for this case. Thanks.