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
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 <forEach>
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
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
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
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.
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.
ASKER