Avatar of dolphin_g
dolphin_g

asked on 

JSP fn:length function not working on LinkedHashMap

Hi,

I'm trying to find the length of a Map by using the fn:length function in JSP. I've used it before, and I'm sure it works. But in the below case, It throws an Exception:

2009-03-17 16:23:59,679 ERROR [org.apache.struts.taglib.tiles.InsertTag] ServletException in '/wealth/portfolio.jsp': Problems calling function 'fn:length'
org.apache.jasper.JasperException: An exception occurred processing JSP page /wealth/portfolio.jsp at line 345

342:                                     </c:if>
343:                               </pg:item>      
344:                               </c:forEach>
345:                               ${fn:length(taxLotSecurityClassMap)}
346:                               <c:if test="${fn:length(taxLotSecurityClassMap) > 1}">
347:                                     <tr>
348:                                           <td align="left" colspan="5" nowrap>&nbsp;</td>


Stacktrace:
      at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:518)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
      ...............
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:595)
Caused by: javax.el.ELException: Problems calling function 'fn:length'
      at org.apache.el.parser.AstFunction.getValue(AstFunction.java:99)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
      at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:928)
      at org.apache.jsp.wealth.portfolio_jsp._jspService(portfolio_jsp.java:1041)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
      ... 59 more
Caused by: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in &lt;forEach&gt;
      at org.apache.taglibs.standard.functions.Functions.length(Functions.java:228)
      at sun.reflect.GeneratedMethodAccessor157.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.el.parser.AstFunction.getValue(AstFunction.java:94)
      ... 65 more

Below attached is the code snippet in JSP. The data structures are

taxLotDetailsMap  - LinkedHashMap<String, LinkedHashMap<String,ArrayList<someObject>>>;

Ive tried to specify in the logic:iterate tag the "type" attribute as 'java.util.LinkedHashMap', it throws an Error:

2009-03-17 16:34:51,862 ERROR [org.apache.struts.taglib.tiles.InsertTag] ServletException in '/wealth/portfolio.jsp': java.util.LinkedHashMap$Entry
org.apache.jasper.JasperException: An exception occurred processing JSP page /wealth/portfolio.jsp at line 178

175:                                           <bean:message key="html.advantageportfolio.columnname.yield"/>
176:                                     </html:link></span></td>
177:                         </tr>
178:                         <logic:iterate id="taxLotSecurityClassMap" name="sessionModel" property="taxLotDetailsMap" type="java.util.LinkedHashMap">
179:                               <tr>
180:                                     <td nowrap align="left" colspan="15">
181:                                           <span class="labeldark">${taxLotSecurityClassMap.key}</span>


Stacktrace:
      at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:518)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      ..................................................................
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassCastException: java.util.LinkedHashMap$Entry
      at org.apache.jsp.wealth.portfolio_jsp._jspService(portfolio_jsp.java:648)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
      ... 59 more

Thanks,
Raja

<logic:iterate id="taxLotSecurityClassMap" name="sessionModel" property="taxLotDetailsMap">
	<tr>
		<td nowrap align="left" colspan="15">
			<span class="labeldark">${taxLotSecurityClassMap.key}</span>
		</td>
	</tr>
	<c:set var="taxLotSymbolMap" value="${taxLotSecurityClassMap.value}"/>
	<c:forEach var="taxLotListMap" items="${taxLotSymbolMap}">
	<pg:item>
		<c:set var="symbol" value="${taxLotListMap.key}"/>
		<c:set var="taxLotList" value="${taxLotListMap.value}"/>
		<c:choose>
			<c:when test="${fn:length(taxLotList) == 1}">
				<c:set var="taxLotLine" value="${taxLotList[0]}"/>
			</c:when>
			<c:otherwise>
				<c:set var="taxLotLine" value="${portfolioTotals[symbol]}"/>
			</c:otherwise>
		</c:choose>
		<tr>
			.....................
			.....................
		</tr>
		<c:if test="${fn:length(taxLotList) > 1}">
			<logic:iterate id="taxLotDetail" indexId="taxLotIndexNumber" collection="${taxLotList}" type="com.vantra.volts.core.session.aspirewealth.portfolio.WealthPortfolioLine">
				<bean:define id="taxLotLineNumber" value="<%= String.valueOf(taxLotIndexNumber.intValue() + 1) %>" type="java.lang.String"/>
				<tr style="display: none;" id="<%=taxLotDetail.getSymbol() + taxLotLineNumber%>">
					....................
					....................
					....................
				</tr>
			</logic:iterate>
		</c:if>
	</pg:item>	
	</c:forEach>
 
	<c:if test="${fn:length(taxLotSecurityClassMap) > 1}">
		<tr>
			<td align="left" colspan="5" nowrap>&nbsp;</td>
			<td align="right" nowrap><hr></td>
			<td>&nbsp;</td>
			<td align="right" nowrap><hr></td>
			<td align="right" nowrap><hr></td>
			<td align="right" nowrap><hr></td>
			<td align="right" nowrap><hr></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td align="right" nowrap><hr></td>
			<td align="right" nowrap><hr></td>
		</tr>
 
	</c:if>	
 
</logic:iterate>

Open in new window

Java EEJSP

Avatar of undefined
Last Comment
dolphin_g
Avatar of dolphin_g
dolphin_g

ASKER

figured this out by myself. I am trying to call the Size function on The Map.Entry instead of on the value of the Map.Entry, the actual map that is returned as the result of iteration on the Map.
Avatar of Manish
Manish
Flag of India image

Can you post that code, that will help others.
ASKER CERTIFIED SOLUTION
Avatar of dolphin_g
dolphin_g

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Java EE
Java EE

Java Enterprise Edition (Java EE) is a specification defining a collection of Java-based server and client technologies and how they interoperate. Java EE specifies server and client architectures and uses profiles to define technology sets targeted at specific classes of applications. All Java EE profiles share a set of common features, such as naming and resource injection, packaging rules and security requirements.

18K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo