I have to display a map of objects in a page.
The Struts action class is as follows:
public class DonorListAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
DonorDAO donorDAO = new DonorDAO();
HashMap<Integer, DonorDetailsForm> donorMap =donorDAO.getDonorList();
request.setAttribute("donorMap",donorMap);
return mapping.findForward("success");
}
}
The jsp page looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<html>
<HEAD><TITLE>List of Donors</TITLE></HEAD>
<body BGCOLOR="#FDF5E6">
<table align="center" border="1">
<tr>
<th align="center">Donor ID</th>
<th align="center">Name</th>
<th align="center">Email Address</th>
<th align="center">Phone Number</th>
</tr>
<c:forEach var="donor" items="${donorMap}">
<tr>
<td align="right">${donor.key}</td>
<td align="right">${donor.value.firstName} ${donor.value.lastName}</td>
<td align="right">${donor.value.emailAddress}</td>
<td align="right">${donor.value.phoneNumber}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
Now when I execute this code I get:
javax.el.PropertyNotFoundException: Property 'key' not found on type java.lang.String javax.el.BeanELResolver$BeanProperties.get(BeanELR esolver.java:193) javax.el.BeanELResolver$BeanProperties.access$400( BeanELResolver.java:170) javax.el.BeanELResolver.property(BeanELResolver.ja va:279) javax.el.BeanELResolver.getValue(BeanELResolver.ja va:60) javax.el.CompositeELResolver.getValue(CompositeELR esolver.java:54) org.apache.el.parser.AstValue.getValue(AstValue.ja va:118) org.apache.el.ValueExpressionImpl.getValue(ValueEx pressionImpl.java:186) org.apache.jasper.runtime.PageContextImpl.propriet aryEvaluate(PageContextImpl.java:925) org.apache.jsp.jsp.DisplayDonorList_jsp._jspx_meth _c_005fforEach_005f0(DisplayDonorList_jsp.java:121 ) org.apache.jsp.jsp.DisplayDonorList_jsp._jspServic e(DisplayDonorList_jsp.java:83) org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet .java:717) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:369) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:322) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:249) javax.servlet.http.HttpServlet.service(HttpServlet .java:717) org.apache.struts.action.RequestProcessor.doForwar d(RequestProcessor.java:1063) org.apache.struts.action.RequestProcessor.processF orwardConfig(RequestProcessor.java:386) org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:229) org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1194) org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:414) javax.servlet.http.HttpServlet.service(HttpServlet .java:617) javax.servlet.http.HttpServlet.service(HttpServlet .java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
What mistake am I doing?