Search code examples
javajspstrutsjstl

JSTL getting values from Object array


My action class has an object array like this:

Object[] varCount = (Object[]) countList.get(0); 

and my debug shows values for varCount. I put this object array in model as follows:

model.put("varCount ", varCount );

and in JSP I iterate as follows:

<c:forEach var="varCount " items="${model.varCount }" varStatus="loop">
  <tr>
     <td align="center">&nbsp;<c:out value="${varCount[0]}"/></td>
  </tr>
</c:forEach>

And I get the following error:

Wrapped exception:
javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${varCount [0]}": Unable to find a value for "0" in object of class "java.math.BigDecimal" using operator "[]" (null)
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:306)
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:16

How do I get the values?


Solution

  • Use like this to get all array objects

    <c:forEach var="item" items="${model.varCount }" varStatus="loop">
     <tr>
     <td align="center">&nbsp;<c:out value="${item}"/></td>
      </tr>
     </c:forEach>