This is probably more of a JSTL question, however I have spent hours debugging and searching online , nothing seems to work..hopefully someone out here could help me with this
I am trying to iterate over an arraylist(newList) which contains a hashmap using jstl. I am using jstl 1.2. The arraylist is populated before being returned to the view. Heres my onSubmit method of my FormController
Following is my code for jsp viewCode:public ModelAndView onSubmit(Object command, BindException errors) throws Exception{ String deviceName = "Site 103"; List<Map> data = new ArrayList<Map>(); Map testData = new HashMap(); testData.put("time","2008-09-27 11:30:00"); testData.put("frequency","143"); data.add(testData); ModelAndView mav = new ModelAndView(new RedirectView(getSuccessView())); mav.addObject("data",data); mav.addObject("name",deviceName); logger.info(mav.toString()); return mav; }
The name shows up , but the list with the hashmap doesnt.Code:<center><b> <c:out value="${param['name']}"/></b></center> <c:forEach items="${paramValues['data']}" var="record" varStatus = "status"> <c:forEach var="val" items="${record.value}"> <c:out value="${record.key}"/> <c:out value="${val}"/> </c:forEach> </c:forEach>
I have tried different ways, but I am probably not using the right syntax here.
Whats frustrating is , in one of my other views, I am using the following jstl
to display map values in a list and that works fine , but the same syntax doesnt work for the view above
Following is the code for my other view and my other controller
Code:<c:forEach items="${model.data}" var="record" varStatus = "status"> <c:out value="${record.time}" /> <c:out value="${record.frequency}" /> </c:forEach>Thanks for looking into this!!Code:public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, Object> myModel = new HashMap<String, Object>(); List<Map> data = new ArrayList<Map>(); Map testData = new HashMap(); testData.put("time","2008-09-27 11:30:00"); testData.put("frequency","143"); data.add(testData); myModel.put("data",data); return new ModelAndView("menu", "model", myModel); }


Reply With Quote

