Reputation: 187
I try to do something easy, but it's not working. Do i miss something obvious ?
my jsp :
<c:if test="${not empty listeApp}">
<table border = "1">
<c:forEach var="apps" items="${listeApp}" >
<tr>
<td>${apps.ID_APPLICATION}</td>
<td>${apps.ID_APPLICATION}</td>
</tr>
</c:forEach>
</table>
my controller :
public ModelAndView portail() {
applicationDao appDAO = new applicationJPADaoImpl();
return new ModelAndView("portail", "listeApp", appDAO.listeAll());
}
Nothing is displayed.
${listeApp[0].ID_APPLICATION}
works.
my list is good, i printed it in the sysout without any prob.
i can get the lenght ${fn:length(listeApp)}
but i would like to use the Foreach feature :)
Any advice ? Thanks
Upvotes: 4
Views: 6848
Reputation: 5067
On a test project I made the following:
Controller code:
@RequestMapping(value = "{id}", method = RequestMethod.GET)
public String getView(@PathVariable Long id, Model model) {
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus", menus);
return "menu/view";
}
JSP Code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Title in Work!</title>
</head>
<body>
<table style="align:center;">
<th>Name</th>
<th>Price</th>
<th>Restaurant</th>
<c:forEach items="${menus}" var="menu">
<tr>
<td><c:out value="${menu.name}"/></td>
<td><c:out value="${menu.price}"/></td>
<td><c:out value="${menu.restaurant.name}"/></td>
</tr>
</c:forEach>
</table>
EDIT
For completions sake:
With success. Hope it helps you!
Upvotes: 1
Reputation: 187
I found the solution : include this in JSP
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
I feel like an idiot :)
Upvotes: 5