JSPページング


package examples;

import java.util.List;
import java.util.ArrayList;

public class PageNumBean {

	private Integer upPageNum; //      

	private Integer downPageNum; //      

	private Integer firstPageNum; //   

	private Integer endPageNum; //   

	private List pages; //          

	private Integer perPageRecordCount; //        

	private Integer currentNum; //     

	private Integer pageCount; //    

	private Integer recordCount; //     

	private Integer beginRecordIndex; //              0  

	private Integer perPageNumCount; //         

	public PageNumBean(int currentNum, int recordCount, int perPageRecordCount,
			int perPageNumCount) {
		this.currentNum = new Integer(currentNum);
		this.perPageRecordCount = new Integer(perPageRecordCount);
		this.recordCount = new Integer(recordCount);
		this.perPageNumCount = new Integer(perPageNumCount);
		setValue();
	}

	public final void setValue() {

		int _page = -1;
		int _perPageRecordCount = -1;
		int _recordCount = -1;
		int _pageCount = -1;
		int _pageNumBegin = -1;
		int _beginIndex = -1;
		int _upPageNum = -1;
		int _downPageNum = -1;
		int _perPageNumCount = -1;
		int _firstPageNum = -1;
		int _endPageNum = -1;

		List _pages = new ArrayList();
		_page = this.currentNum.intValue();
		_perPageRecordCount = this.perPageRecordCount.intValue();
		_recordCount = this.recordCount.intValue();
		_perPageNumCount = this.perPageNumCount.intValue();
		_pageCount = _recordCount / _perPageRecordCount
				+ (_recordCount % _perPageRecordCount == 0 ? 0 : 1); //        
		_pageNumBegin = ((_page - 1) / _perPageNumCount) * _perPageNumCount + 1;

		for (int i = 0; i < _perPageNumCount && _pageNumBegin <= _pageCount; i++) {
			String pageNum = String.valueOf(_pageNumBegin);
			_pages.add(pageNum);
			_pageNumBegin++;
		}

		_beginIndex = (_page - 1) * _perPageRecordCount;
		
		if (_pageCount != -1 && _page != 1) {
			_firstPageNum = 1;
		}

		if (_page > 1) {
			_upPageNum = _page - 1;
		}

		if (_page + 1 <= _pageCount) {
			_downPageNum = _page + 1;
		}

		if (_pageCount != -1) {
			this.pageCount = new Integer(_pageCount);
		}

		if (_beginIndex != -1) {
			this.beginRecordIndex = new Integer(_beginIndex);
		}

		if (_upPageNum != -1) {
			this.upPageNum = new Integer(_upPageNum);
		}

		if (_downPageNum != -1) {
			this.downPageNum = new Integer(_downPageNum);
		}

		if (_firstPageNum != -1) {
			this.firstPageNum = new Integer(_firstPageNum);
		}

		if (_pageCount != -1 && _page != _pageCount) {
			this.endPageNum = new Integer(_pageCount);
		}

		this.pages = _pages;
	}

	public Integer getBeginRecordIndex() {
		return beginRecordIndex;
	}

	public void setBeginRecordIndex(Integer beginRecordIndex) {
		this.beginRecordIndex = beginRecordIndex;
	}

	public Integer getPageCount() {
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public Integer getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(Integer recordCount) {
		this.recordCount = recordCount;
	}

	public Integer getCurrentNum() {
		return currentNum;
	}

	public void setCurrentNum(Integer currentNum) {
		this.currentNum = currentNum;
	}

	public Integer getDownPageNum() {
		return downPageNum;
	}

	public void setDownPageNum(Integer downPageNum) {
		this.downPageNum = downPageNum;
	}

	public List getPages() {
		return pages;
	}

	public void setPages(List pages) {
		this.pages = pages;
	}

	public Integer getPerPageRecordCount() {
		return perPageRecordCount;
	}

	public void setPerPageRecordCount(Integer perPageRecordCount) {
		this.perPageRecordCount = perPageRecordCount;
	}

	public Integer getUpPageNum() {
		return upPageNum;
	}

	public void setUpPageNum(Integer upPageNum) {
		this.upPageNum = upPageNum;
	}

	public Integer getFirstPageNum() {
		return firstPageNum;
	}

	public void setFirstPageNum(Integer firstPageNum) {
		this.firstPageNum = firstPageNum;
	}

	public Integer getEndPageNum() {
		return endPageNum;
	}

	public void setEndPageNum(Integer endPageNum) {
		this.endPageNum = endPageNum;
	}

	public Integer getPerPageNumCount() {
		return perPageNumCount;
	}

	public void setPerPageNumCount(Integer perPageNumCount) {
		this.perPageNumCount = perPageNumCount;
	}
}
  
<c:set value="../myServlet?action=${requestScope.action}&beginDate=${requestScope.beginDate}&endDate=${requestScope.endDate}&page=" var="pageUrl" />
    				 			    
 <c:choose>
	<c:when test="${not empty requestScope.pageNumBean.firstPageNum}">
		<a href="${pageUrl}${requestScope.pageNumBean.firstPageNum}">  </a>
	</c:when>
	<c:otherwise>
		  
	</c:otherwise>
</c:choose>
									
<c:choose>
	<c:when test="${not empty requestScope.pageNumBean.upPageNum}">
		<a href="${pageUrl}${requestScope.pageNumBean.upPageNum}">   </a>
	</c:when>
	<c:otherwise>
		   
	</c:otherwise>
</c:choose>
								
<c:forEach items="${requestScope.pageNumBean.pages}" var="item">
	<c:choose>
		<c:when test="${item == requestScope.pageNumBean.currentNum}">
			<a href="${pageUrl}${item}">[${item}]</a>
		</c:when>
		<c:otherwise>
			<a href="${pageUrl}${item}">${item}</a>
		</c:otherwise>
	</c:choose>											
</c:forEach>
								
<c:choose>
	<c:when test="${not empty requestScope.pageNumBean.downPageNum}">
		<a href="${pageUrl}${requestScope.pageNumBean.downPageNum}">   </a>
	</c:when>
	<c:otherwise>
		   
	</c:otherwise>
</c:choose>
								
<c:choose>
	<c:when test="${not empty requestScope.pageNumBean.endPageNum}">
		<a href="${pageUrl}${requestScope.pageNumBean.endPageNum}">  </a>
	</c:when>
	<c:otherwise>
		  
	</c:otherwise>
</c:choose>
のJSPのラベルはJSTLです