Tuesday, May 17, 2005

Conditional display of table data

This code snippet makes use of JSTL core taglib to display no data found if the table contains no records, else it display the records.

------------------------------------
<table border="1" width="100%">
<tr>
<th> </th>
<th>
<c:out value="${bindings.DummyView1.labels['Field1']}"/>
</th>
<th>
<c:out value="${bindings.DummyView1.labels['Field2']}"/>
</th>
<th>
<c:out value="${bindings.DummyView1.labels['Field3']}"/>
</th>
</tr>
<c:choose>
<c:when test="${bindings.DummyView1Iterator.estimatedRowCount>0}">
<c:forEach var="Row" items="${bindings.DummyView1.rangeSet}">
<tr>
<td>
<c:out value="${Row.currencyString}"/>
</td>
<td>
<c:out value="${Row['Field1']}"/> 
</td>
<td>
<c:out value="${Row['Field2']}"/> 
</td>
<td>
<c:out value="${Row['Field3']}"/> 
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td colspan="4">no data found</td>
</tr>
</c:otherwise>
</c:choose>
</table>

No comments: