Reputation: 81
I reviewed previous examples on this site and I couldn't get anything to work. I also googled my dilemma but had no success.
I'm trying to debug some code here. I can seem to drop the last comma. Thoughts?
<c:forEach items="${userDeptList}" var="userDeptVar" varStatus="userDeptCounter" >
<c:if test="${contactsVar.userId==userDeptVar.userID}">
<c:forEach items="${deptPtypeList}" var="deptsVar" varStatus="deptsCounter" >
<c:if test="${deptsVar.ptypeID==userDeptVar.deptID}">
<c:out value="${deptsVar.type}" escapeXml="false"></c:out>
<c:out value="," escapeXml="false"></c:out>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
Upvotes: 0
Views: 1728
Reputation: 240908
use varStatus
<c:if test="${not deptsCounter.last}">
</c:if>
Upvotes: 0
Reputation: 7807
To omit the final comma you can test if you are on the last item in this way
<c:forEach items="${userDeptList}" var="userDeptVar" varStatus="userDeptCounter" >
<c:if test="${contactsVar.userId==userDeptVar.userID}">
<c:forEach items="${deptPtypeList}" var="deptsVar" varStatus="deptsCounter" >
<c:if test="${deptsVar.ptypeID==userDeptVar.deptID}">
<c:out value="${deptsVar.type}" escapeXml="false"></c:out>
<c:if test="${not userDeptCounter.last}>
<c:out value="," escapeXml="false"></c:out>
</c:if>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
Here a list of all varStatus properties
current The item (from the collection) for the current round of iteration
index The zero-based index for the current round of iteration
count The one-based count for the current round of iteration
first Flag indicating whether the current round is the first pass through the iteration
last Flag indicating whether the current round is the last pass through the iteration
begin The value of the begin attribute
end The value of the end attribute
step The value of the step attribute
Upvotes: 1