I'm trying to build simple MVC spring web app from this source :
https://javapipe.com/spring-mvc-web-application-tutorial-with-examples-part-1
I tried to retrieve the list of Purchase Requests & set it to model attribute however on the view it's only showing the jstl tag without its value E.g ${request.poNumber}
Here's my Controller snippet :
@Controller
@RequestMapping("/purchase-request")
public class PurchaseRequestController {
private static final String MY_REQUESTS_VIEW = "myRequests";
private static final String MY_REQUESTS_MODEL_ATTRIBUTE = "myRequestList";
@Resource
private PurchaseRequestService purchaseRequestService;
@RequestMapping(value = "/myRequests", method = RequestMethod.GET)
public String getMyRequests(Model model){
System.out.println("Data g: "+purchaseRequestService.getAllPurchaseRequests().get(0).getPoNumber());
model.addAttribute(MY_REQUESTS_MODEL_ATTRIBUTE, purchaseRequestService.getAllPurchaseRequests());
return MY_REQUESTS_VIEW;
}
}
it's my view (myRequests.jsp) :
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Requests</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="myRequestList" scope="request" type="java.util.List" />
</head>
<body>
<c:if test="${not empty myRequestList}">
Hello
<ul>
<c:forEach var="listValue" items="${myRequestList}">
<li>${listValue}</li>
</c:forEach>
</ul>
</c:if>
<div class="container-fluid">
<div class="page-header">
<h1>Purchase Requests</h1>
</div>
<div class="row">
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#">Saved</a></li>
<li role="presentation"><a href="#">Submitted</a></li>
<li role="presentation"><a href="#">Approved</a></li>
</ul>
</div>
<div class="row">
<table class="table">
<thead>
<tr>
<th>PO Number</th>
<th>Date</th>
<th>Justification</th>
</tr>
</thead>
<tbody>
<c:forEach items="${myRequestList}" var="request">
<tr>
<td>${request.poNumber}</td>
<td>${request.date}</td>
<td>${request.justification}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</body>
</html>
my POM.xml :
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
I tried to print out value of the list in the Controller, it's shown correctly in the Eclipse console, but not in the view.
Is there something I missed here?
Thanks in advance