I have 2 models being used in jsp:
<c:forEach items="${ch}" var="contractHeader">
Display data ...
<table>
Display TD
<c:forEach items="${ce}" var="contractEntitlement">
<c:if test="${contractHeader.id == contractEntitlement.chId}" >
Display TR
</c:if>
</c:forEach>
</c:forEach>
Based from this, it will only show the records if id from contractHeader is equal to chid from contractEntitlement. This works but the problem is if there is no records for contractEntitlement the TD still shows with empty table.
I want to add a extra condition for TD using boolean to do something like:
boolean test = false;
<c:forEach items="${ce}" var="contractEntitlement">
<c:if test="${contractHeader.id == contractEntitlement.chId}" >
test = true;
exit loop;
</c:if>
</c:foreach>
if (test)
<table>
Show TD
Use exisiitng code to loop thru each records
</table>
Output is, if there are no records dont create the table at all, Any help is appreciated.
First of all, I think the TR should be outside of TD. You have TD outside of TR, which is wrong. Other than that, my attempt for a workaround would be to try to bring TD inside if statement? like this:
<forEach ....>
<table>
<c:forEach items="${ce}" var="contractEntitlement">
<c:if test="${contractHeader.id == contractEntitlement.chId}" >
Display TR
Display TD .... END OF DISPLAY TD
Display TR, end of
</c:if>
</c:forEach>
</table>
</forEach ...>
Edit:
Or if you want to keep your table structure as is, then you can try to use CSS to hide empty cells/columns.
Give your table a class like this:
table class="myTable"
Then, use this CSS
inside <head> ... </head>
<style>
.myTable{
empty-cells: hide;
}
</style>
Play around like this and I am sure you will be able to hide TD...
Edit 2:
Upon reading further comments by the OP, the OP should try to bring the whole table creation thing inside if statement. When if statement is true, only then a new table will be created. It would look something like this:
<forEach ....>
<c:forEach items="${ce}" var="contractEntitlement">
<c:if test="${contractHeader.id == contractEntitlement.chId}" >
<table>
Display TR
Display TD .... END OF DISPLAY TD
Display TR, end of
</table>
</c:if>
</c:forEach>
</forEach ...>