I am trying to implement a custom JSP tag that takes Collection objects as an attribute and displays them as an array in JSON format (each object in Collection provides a getJsonString() method that returns a JSON formatted representation of this object). I use my tag as such:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ attribute name="objects" required="true" rtexprvalue="true" %> <c:set var="output" value="" /> <c:forEach var="obj" items="${objects}"> <c:if test="${! empty showComma}"> <c:set var="output" value="${output}, " /> </c:if> <c:set var="output" value="${output}${obj.jsonString}" /> <c:set var="showComma" value="yes" /> </c:forEach> [${output}]
... and I want to use it by doing something like:
<myTaglib:jsonArray objects="${myCollection}" />
However, when I try to use a tag, I get a stack trace:
javax.el.PropertyNotFoundException: Property 'jsonString' not found on type java.lang.String
So he complains about the expression ${obj.jsonString} , but I definitely don't pass the Collection strings. Moreover, if I change it to ${obj} , I see that the correct types of objects are displayed, and if I copy / paste the code for my custom tag in the JSP where I want to use it, it works correctly, so I really donβt know what's going on here.
I assume there is some problem with the way I pass Collection to a custom tag, but I cannot figure out what it is. Any ideas?
source share