I want to create a table with a variable amount of trackers which have a variable amount of trackable devices attached to them. I want to display that in my JSP file.
I have tried calling the lists with
<c:forEach items="${tracker.getTrackableDeviceList()}" var="trackableDevice">
, but I get the error:
"Unknown column 't0.trackableDeviceList_ID' in 'where clause'".
When I use <td> <c:out value="${tracker.getTrackableDeviceList()}"/> </td>
it works but it says the list wasn't instantiated. Which is strange since the trackerList works fine.
Last but not least I have tried to create an atribut trackerList for all trackers and an atribut trackableDeviceList for every tracker in trackerList. I wanted to match the atributs with the JSP by using the trackerId, but I've reaceived the error:
Stacktrace:] with root cause
javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
I found something similar javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach> but it doesn't realy help me (or I just don't get it).
How can I manage to iterate through this? Any kind of advice is appreciated. I cut the error and code down to the relevant parts...
JSP
<form method="post" action="TrackerList_Servelet">
<table>
<c:forEach items="${trackerList}" var="tracker">
<tr>
<td> <c:out value="${tracker.getPiName()}"/> </td>
<td> <c:out value="${tracker.getTrackableDeviceList()}"/> </td>
<c:forEach items="${tracker.getTrackerId()}" var="trackableDevice"> <!-- How to iterate through this? -->
<td>
<td> <c:out value="${trackableDevice.getId()}"/> </td>
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
<input type="submit" value="Update"/>
</form>
Servelet
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
DataManager dataManager = new DataManager();
dataManager.startDataManagerSetup();
//Prepare the trackerList
List<Tracker> trackerList = dataManager.getTrackerList();
request.setAttribute("trackerList", trackerList); // Will be available as ${trackerList} in JSP
//Prepare the trackableDeviceList for every tracker in trackerList
for(int i = 0; i < trackerList.size(); i++)
{
Tracker t = trackerList.get(i);
List<TrackableDevice> trackableDeviceList = t.getTrackableDeviceList();
String trackerId = Integer.toString(t.getTrackerId());
request.setAttribute(trackerId, trackableDeviceList); // Will be available as ${trackableDeviceList} in JSP
}
//Answer the request by sending back the list to status.jsp
request.getRequestDispatcher("status.jsp").forward(request, response);
}