I try to create a jsp tag file, which will call a helper class to print the input object. So I created a file /WEB-INF/tags/formatter.tag
<%@ tag import="package.Formatter"%>
<%@ attribute name="value" required="true" type="java.lang.Object" %>
<%=Formatter.format(pageContext.getAttribute("value"))%>
So that I can call it in JSP like:
<t:formatter value="${obj}" />
But I found that it will not work inside a loop, e.g.
<c:forEach items="${list}" var="i">
<t:formatter value="${i.property}"/>
</c:forEach>
I suspect that I should not get the attribute from pageContext
. But I'm not sure. Any one know about this?