Reputation: 5459
I currently am making a table which has 8 columns. To start, I check if the value is null, if not null I write out a column title for the column (ex: "First Name:"). Next, I cycle through a list and populate each column with the appropriate value if it is not null. My issue is that the column headers (in between the comments in the code below) does not print while the actual data in the table does print. Can anyone help me?
<table style="width: 100%">
<c:choose>
<c:when test="${empty serviceRequests}">
</c:when>
<c:otherwise>
<tr> //DOES NOT PRINT STARTING FROM HERE
<td><c:choose>
<c:when test="${empty serviceRequestData['ID']}"></c:when>
<c:otherwise>
<u>ID:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['FN_Contact']}"></c:when>
<c:otherwise>
<u>First Name:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['LN_Contact']}"></c:when>
<c:otherwise>
<u>Last Name:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Email']}"></c:when>
<c:otherwise>
<u>Email:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['FN_Reporter']}"></c:when>
<c:otherwise>
<u>Reporter First Name:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['LN_Reporter']}"></c:when>
<c:otherwise>
<u>Reporter Last Name:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Company']}"></c:when>
<c:otherwise>
<u>Company:</u>
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Notes']}"></c:when>
<c:otherwise>
<u>Notes:</u>
</c:otherwise>
</c:choose></td>
</tr> //DOES NOT PRINT ENDING HERE
<c:forEach var="serviceRequestData" items="${serviceRequests}">
<tr>
<td><c:choose>
<c:when test="${empty serviceRequestData['ID']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['ID']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['FN_Contact']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['FN_Contact']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['LN_Contact']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['LN_Contact']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Email']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['Email']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['FN_Reporter']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['FN_Reporter']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['LN_Reporter']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['LN_Reporter']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Company']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['Company']}
</c:otherwise>
</c:choose></td>
<td><c:choose>
<c:when test="${empty serviceRequestData['Notes']}">
Null
</c:when>
<c:otherwise>
${serviceRequestData['Notes']}
</c:otherwise>
</c:choose></td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
Upvotes: 0
Views: 1168
Reputation: 63676
The variable you are trying to access in the table headers isn't defined until the <c:forEach>
used to iterate over the data rows.
This should work:
<table style="width: 100%">
<c:choose>
<c:when test="${empty serviceRequests}"></c:when>
<c:otherwise>
<tr>
<td>
<u>ID:</u>
</td>
<td>
<u>First Name:</u>
</td>
<td>
<u>Last Name:</u>
</td>
<td>
<u>Email:</u>
</td>
<td>
<u>Reporter First Name:</u>
</td>
<td>
<u>Reporter Last Name:</u>
</td>
<td>
<u>Company:</u>
</td>
<td>
<u>Notes:</u>
</td>
</tr>
<c:forEach var="serviceRequestData" items="${serviceRequests}">
...
</c:forEach>
</c:otherwise>
</c:choose>
</table>
Of course you'll need to figure out what logic, (if any) that you want to use to wrap the header values.
Upvotes: 1