pagination.jsp
来自「一个很好的开源项目管理系统源代码」· JSP 代码 · 共 147 行
JSP
147 行
<%@ page import="java.util.List, javax.servlet.jsp.PageContext, org.apache.taglibs.datagrid.Page" %><% /* * Unfortunately the datagrid does not expose all the variables we need for the * page navigations. Need this to create navigations links for 'lastPage' * 'firstpage' and the page links. */ int pageSize = ((Integer)request.getAttribute("pageSize")).intValue(); int rowCount = ((Integer)request.getAttribute("rowCount")).intValue(); List pageList= (List) pageContext.getAttribute("pages"); if (pageList != null && pageList.size() > 0){ pageContext.setAttribute("first", ((Page)pageList.get(0)).getUrl()); pageContext.setAttribute("last", ((Page)pageList.get(pageList.size()-1)).getUrl()); int currentPageIdx = 0; String rowIdxStr = (String) request.getParameter("p_datagrid_app_page_index"); if (rowIdxStr != null) currentPageIdx= new Integer(rowIdxStr).intValue()/pageSize; pageContext.setAttribute("currentPageIdx", new Integer(currentPageIdx)); // Number of page links to be displayed. int LINK_COUNT = 8; int beginPageIdx = currentPageIdx - (currentPageIdx%LINK_COUNT); int endPageIdx = beginPageIdx + LINK_COUNT -1; if (endPageIdx > pageList.size()-1) endPageIdx = pageList.size()-1; pageContext.setAttribute("beginPageIdx", new Integer(beginPageIdx)); pageContext.setAttribute("endPageIdx", new Integer(endPageIdx)); pageContext.setAttribute("beginRow", new Integer(currentPageIdx*pageSize +1)); int endRow = currentPageIdx * pageSize + pageSize; if (endRow > rowCount) endRow = rowCount; pageContext.setAttribute("endRow", new Integer(endRow)); String more = ""; if (endPageIdx < pageList.size()-1) more = "..."; pageContext.setAttribute("more", more); }%><%-- Display the page navigations --%><br /><c:choose> <c:when test='${empty pages}' > <fmt:message key="paging.item.noDataFound"/> </c:when> <c:otherwise> <c:choose> <c:when test='${rowCount == 1 }' > <fmt:message key="paging.item.oneFound"/> </c:when> <c:otherwise> <c:choose> <c:when test='${rowCount <= pageSize }' > <fmt:message key="paging.item.allFound"/> </c:when> <c:otherwise> <fmt:message key="paging.item.banner"> <fmt:param value="${rowCount}" /> <fmt:param value="${beginRow}" /> <fmt:param value="${endRow}" /> </fmt:message> <br /> <%-- add "rowCount" parameter to the urls if not present --%> <c:choose> <c:when test='${empty param.rowCount}' > <c:set var="nextUrl" value="${next}&rowCount=${rowCount}" /> <c:set var="previousUrl" value="${previous}&rowCount=${rowCount}" /> <c:set var="firstUrl" value="${first}&rowCount=${rowCount}" /> <c:set var="lastUrl" value="${last}&rowCount=${rowCount}" /> </c:when> <c:otherwise> <c:set var="nextUrl" value="${next}" /> <c:set var="previousUrl" value="${previous}" /> <c:set var="firstUrl" value="${first}" /> <c:set var="lastUrl" value="${last}" /> </c:otherwise> </c:choose> <div id="pagination" > <table> <tr> <td nowrap > <c:choose> <c:when test="${previous != null}"> <a href="<c:out value="${firstUrl}"/>"> <img src="<spring:theme code="firstOn.img" />" class="icon" alt="<spring:message code="firstOn.alt" />" /></a> <a href="<c:out value="${previousUrl}"/>"> <img src="<spring:theme code="previousOn.img" />" class="icon" alt="<spring:message code="previousOn.alt" />" /></a> </c:when> <c:otherwise> <img src="<spring:theme code="firstOff.img" />" class="icon" /> <img src="<spring:theme code="previousOff.img" />" class="icon" /> </c:otherwise> </c:choose> </td> <td nowrap> <c:forEach items="${pages}" var="page" begin="${beginPageIdx}" end="${endPageIdx}" > <c:choose> <c:when test="${page.current}"> <c:choose> <c:when test='${empty param.rowCount}' > <b><a href="<c:out value="${page.url}&rowCount=${rowCount}"/>"><c:out value="${page.index}"/></a></b> </c:when> <c:otherwise> <b><a href="<c:out value="${page.url}"/>"><c:out value="${page.index}"/></a></b> </c:otherwise> </c:choose> </c:when> <c:otherwise> <c:choose> <c:when test='${empty param.rowCount}' > <a href="<c:out value="${page.url}&rowCount=${rowCount}"/>"><c:out value="${page.index}"/></a> </c:when> <c:otherwise> <a href="<c:out value="${page.url}"/>"><c:out value="${page.index}"/></a> </c:otherwise> </c:choose> </c:otherwise> </c:choose> </c:forEach> <c:out value="${more}" /> </td> <td nowrap> <c:choose> <c:when test="${next != null}"> <a href="<c:out value="${nextUrl}"/>"> <img src="<spring:theme code="nextOn.img" />" class="icon" alt="<spring:message code="nextOn.alt" />" /></a> <a href="<c:out value="${lastUrl}"/>"> <img src="<spring:theme code="lastOn.img" />" class="icon" alt="<spring:message code="lastOn.alt" />" /></a> </c:when> <c:otherwise> <img src="<spring:theme code="nextOff.img" />" class="icon" /> <img src="<spring:theme code="lastOff.img" />" class="icon" /> </c:otherwise> </c:choose> </td> </tr> </table> </div> </c:otherwise> </c:choose> </c:otherwise> </c:choose> </c:otherwise></c:choose>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?