So I am trying to loop through a map which I retrieve from a Viewable
. It's working with single attributes or whatever but somehow it doesn't allow me to loop through a list. Any suggestions?
If you got a better idea passing objects than using Viewable feel free to let me know!
Thank you guys in advance.
Controller:
@GET
@Path("home")
public Viewable showHome() {
Map <String, Location> map = init();
return new Viewable("/WEB-INF/home.jsp", map);
}
private HashMap init() {
Map <String, Location> map = new HashMap <String, Location>();
Location location1 = new Location("A");
Location location2 = new Location("B");
map.put("1", location1);
map.put("2", location2);
return (HashMap) map;
}
home.jsp code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:if test="${it != null}">
<c:forEach var="location" items="${it}">
Location: <c:out value="${location.name}" />
</c:forEach>
</c:if>
</body>
</html>