Reputation: 121
I am trying to display a list and every object of that list has another list which I have to display, the values are coming but are not being displayed, below is the code I have tried if someone could identify what I am doing wrong, it will be very helpful. I am using Spring MVC but I don't think it has anything to do with this error, any help will be appreciated.
@Entity
@Table(name="FILE_TRACKING_MANAGEMENT")
@NamedQuery(name="FileTrackingManagement.findAll", query="SELECT f FROM FileTrackingManagement f")
{
@OneToMany(mappedBy="fileTrackingManagement")
private List<FileNoting> fileNotings;
//bi-directional many-to-one association to FileTrackingFile
@OneToMany(mappedBy="fileTrackingManagement")
private List<FileTrackingFile> fileTrackingFiles;
}
My Controller Class:
@RequestMapping("viewMarkedFiles/list")
public ModelAndView viewMarkedFiles(Model model)
{
List<FileTrackingManagement> markedFileList= fileService.getList();
//model.addAttribute("markedFileList", markedFileList);
return new ModelAndView("viewMarkedFiles", "markedFileList", markedFileList);
}
My JSP Page:
<table border="1" bgcolor="black" width="600px">
<c:forEach items="${markedFileList}" var="markedFileVal">
<%-- <c:set var="fileNotings" value="${jobs[i.index].jobId}"/> --%>
<tr
style="background-color: white; color: black; text-align: center;"
height="30px">
<td><c:out value="${markedFileVal.diarynumber}" />
<td><c:out value="${markedFileVal.subject}" />
<td>
</td>
<td>
</td>
<td>
<c:forEach items="${markedFileList.fileNotings}" var="filenotings">
<c:out value="${filenotings.notingData}" /></c:forEach>
</td>
</c:forEach>
</table>
It throws this exception:
45: <%-- <c:out value="${fileVal.description}" /> --%>
46: </td>
47: <td>
48: <c:forEach items="${markedFileList.fileNotings}" var="filenotings">
49: <c:out value="${filenotings.notingData}" /></c:forEach>
50:
51:
Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "fileNotings"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
Thanks in advance
Upvotes: 1
Views: 407
Reputation: 121
@OneToMany(fetch = FetchType.EAGER, mappedBy="fileTrackingManagement") private List fileNotings;
The value of fetchType is Lazy by default, when I changed its value, it worked
Upvotes: 0
Reputation: 692181
<c:forEach items="${markedFileList}" var="markedFileVal">
So, you're iterating oover the list markedFileList
. Inside the body of the tag, the current element is markedFileVal
.
Then you do
<c:forEach items="${markedFileList.fileNotings}" var="filenotings">
So you're ietarting over markedFileList.fileNotings
. But markedFileList
is a list. It's not the current element. What you want is
<c:forEach items="${markedFileVal.fileNotings}" var="filenoting">
Also note that I removed the final s
from filenotings
. This variable points to a single filenoting. Not to several ones.
Upvotes: 2