I have a JSP where I am declaring an integer value
<c:set var="rowCount" value="0" />
I am trying to use it inside several tags
<product:attribute rowCount="${rowCount}" attrKey="${msg_site}:" attrValue="${product.site}" />
<product:attribute rowCount="${rowCount}" attrKey="${msg_name}:" attrValue="${product.name}" />
<product:attribute rowCount="${rowCount}" attrKey="${msg_type}:" attrValue="${product.type}" />
Inside each tag I am overriding the rowCount value
<%@ attribute name="rowCount" required="true" %>
<c:if test="${rowCount >= 2}" >
</div>
<div class="col-md-12 col-sm-12 col-xs-12 ">
<c:set var="rowCount" value="${0}" />
</c:if>
<c:set var="rowCount" value="${rowCount +1}" />
But it seems I am declaring a new variable for rowCount in each tag. How do I reuse the value instead of declaring a new variable?
I was trying with adding the scope for only the first declaration of the variable and it was not working.
Then I tried to add for them all, like this:
and
It worked partially. I was able to add new values to the row count, but the line
Was not working. It never went back to zero. So I change it to have a local variable and override the value only once. like this:
Now I have the result that I want. But I still could not understand why I could not override it twice.