java - Iterating a List of Hashmap which is also a list of hashmap Using jstl -
consider iteration below: requestscope.scriptdataset
of type
list<hashmap<string, list<hashmap<string, object>>>>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@page contenttype="text/html" pageencoding="utf-8"%> <c:foreach var="objdatatable" items="${requestscope.scriptdataset}"> <c:if test="${not empty objdatatable['vwcmstreevwdata']}"> <c:foreach var="objrecord" items="${objdatatable['vwcmstreevwdata']}"> <c:foreach var="record" items="${objrecord}"> <c:out value="${record['childname']}"/> </c:foreach> </c:foreach> </c:if> </c:foreach>
i want value of innermost hashmap key failing shown below.
may 17, 2014 8:51:16 pm org.apache.catalina.core.applicationdispatcher invoke severe: servlet.service() servlet jsp threw exception javax.el.propertynotfoundexception: property 'childname' not found on type java.util.hashmap$entry @ javax.el.beanelresolver$beanproperties.get(beanelresolver.java:266) @ javax.el.beanelresolver$beanproperties.access$300(beanelresolver.java:243) @ javax.el.beanelresolver.property(beanelresolver.java:353) @ javax.el.beanelresolver.getvalue(beanelresolver.java:97) @ org.apache.jasper.el.jasperelresolver.getvalue(jasperelresolver.java:104) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:183) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) @ org.apache.jasper.runtime.pagecontextimpl.proprietaryevaluate(pagecontextimpl.java:967) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fout_005f0(menudetails_jsp.java:221) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f2(menudetails_jsp.java:190) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f1(menudetails_jsp.java:150) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f0(menudetails_jsp.java:110) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspservice(menudetails_jsp.java:72) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldo
in code shown above if change <c:out value="${record['childname']}"/>
<c:out value="${record}"/>
displaying data of inner list assures me iteration okay how should values of inner hashmap key. assistance appreciated.
edit
in code above
if change<c:out value="${record['childname']}"/>
<c:out value="${record.key}"/>
it displays keys
if change<c:out value="${record['childname']}"/>
<c:out value="${record.value}"/>
it displays values
if change<c:out value="${record['childname']}"/>
<c:foreach var="entry" items="${record}" >
<c:out value="${entry.key}"/>
</c:foreach>
it complains:
may 18, 2014 10:02:16 org.apache.catalina.core.applicationdispatcher invoke severe: servlet.service() servlet jsp threw exception javax.servlet.jsp.jsptagexception: don't know how iterate on supplied "items" in <foreach> @ org.apache.taglibs.standard.tag.common.core.foreachsupport.toforeachiterator(foreachsupport.java:312) @ org.apache.taglibs.standard.tag.common.core.foreachsupport.supportedtypeforeachiterator(foreachsupport.java:276) @ org.apache.taglibs.standard.tag.common.core.foreachsupport.prepare(foreachsupport.java:193) @ javax.servlet.jsp.jstl.core.looptagsupport.dostarttag(looptagsupport.java:291) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f3(menudetails_jsp.java:226) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f2(menudetails_jsp.java:190) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f1(menudetails_jsp.java:150) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspx_meth_c_005fforeach_005f0(menudetails_jsp.java:110) @ org.apache.jsp.web_002dinf.views.menudetails_jsp._jspservice(menudetails_jsp.java:72) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) @ javax.servlet.http.httpservlet.service(httpservlet.java:727)
i changed code from
<%@page contenttype="text/html" pageencoding="utf-8"%> <c:foreach var="objdatatable" items="${requestscope.scriptdataset}"> <c:if test="${not empty objdatatable['vwcmstreevwdata']}"> <c:foreach var="objrecord" items="${objdatatable['vwcmstreevwdata']}"> <c:foreach var="record" items="${objrecord}"> <c:out value="${record['childname']}"/> </c:foreach> </c:foreach> </c:if> </c:foreach>
to
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@page contenttype="text/html" pageencoding="utf-8"%> <c:foreach var="objdatatable" items="${requestscope.scriptdataset}"> <c:if test="${not empty objdatatable['vwcmstreevwdata']}"> <c:foreach var="objrecord" items="${objdatatable['vwcmstreevwdata']}"> <c:out value="${objrecord['childname']}"/> </c:foreach> </c:if> </c:foreach>
and working. members of "anti-jsp scriptlets" camp-proponents of jstl must must explain. thanks.
Comments
Post a Comment