Tom Wally Tom Wally - 1 month ago 7
Java Question

Override variables in JSTL

I'm trying to make pagination.

I have some variable

get_page_num
:



<c:set var="get_page_num"/>

<spring:url value="" var="pageurl">
<spring:param name="page" value="${get_page_num}" />
<spring:param name="size" value="${page.size}" />
</spring:url>


After that, I'm trying to generate the url:

<li><a href="${pageurl}">7</a></li>
<li><a href="${pageurl}">8</a></li>


How can I put 7 or 8 value (number of page) to
get_page_num
variable. I need to override it.

Answer

Values 7,8 are already generated, you can get em only with javascript.

Use parameter in the url

<li><a href="${pageurl}?get_page_num=7">7</a></li> 

In more sophisticated code you can write

<spring:url value="" var="pageurl" />
<c:forEach begin="1" end="${page.size}" varStatus="status">
 <c:if test="${get_page_num == status.current}">
   ${status.current}&nbsp;
 </c:if>
 <c:if test="${get_page_num != status.current}">
   <li><a href="${pageurl}?get_page_num=${status.current}">${status.current}&nbsp;</a></li>
 </c:if>
</c:forEach>