Friday, 19 April 2013

Getting size of a map in JSTL (it's different in JSP2.1 and JSP 2.2)

Surprised to discover that this doesn't cause problems in JSP

<c:out value="${priceMap.lenght}"/>

tried fixing it to


then realised it gets converted to getSize() and so changed to


and then get a JSP exception:

org.apache.jasper.JasperException: /WEB-INF/jsp/postform.jsp(31,22)
The function getSize must be used with a prefix when a default
namespace is not specified

I was wondering why, then realised that this works in JSP 2.2
(released in 2009) but not in JSP 2.1 (released 2006)

In JSP 2.1 you must use:

<%@ taglib uri="" prefix="c"%>
<%@ taglib uri="" prefix="fn"%>

<c:out value="${fn:length(priceMap)}" />

No comments: