/**
* 分页组件
*
* @author
*
*/
public class LucenePage {
private int currentPage = 1;
private int pageSize = 15;
private int totalRecords = 1;
String pageUrl = "";
/**
* 构造函数
*
* @param curPage
* 当前页
* @param pageSize
* 每页显示条数
* @param url
* 页面url
* @param totalRecord
* 总记录数
*/
public LucenePage(int curPage, int pageSize, String url, int totalRecord) {
this.currentPage = curPage;
this.pageSize = pageSize;
this.totalRecords = totalRecord;
this.pageUrl = url;
}
/**
* 打印 共 条 分 页 当前第1页 首页 上一页 下一页 末页
*
* @return
*/
public String getPageFooter() {
StringBuffer pageFooter = new StringBuffer();
int totalPages = (totalRecords % pageSize) == 0 ? totalRecords / pageSize : (totalRecords / pageSize) + 1;
int previousPage = this.currentPage == 1 ? 1 : this.currentPage - 1;
int nextPage = this.currentPage >= totalPages ? totalPages : this.currentPage + 1;
pageFooter.append("\n<div class='pagenav'>");
pageFooter.append("\n\t<form name='fsmformvalue' action='" + this.pageUrl
+ "' method='post'>");
String style = "";
if (totalPages == 1) {
style = "disabled";
}
pageFooter.append("\n\t\t<span id='pagenavcount'>共<b>" + totalRecords + "</b>条</span>");
pageFooter.append("\n\t\t<span id='pagenavpagecount'>分<b>" + totalPages + "</b>页</span>");
pageFooter.append("\n\t\t<span id='pagenavcurrpage'>当前 第<b>" + this.currentPage + "</b>页</span>");
// 为首页时处理
if ( this.currentPage <= 1) {
pageFooter.append("\n\t\t <span class='pagenavnav1'>首页</span>");
pageFooter.append("\n\t\t <span class='pagenavnav1'>上一页</span>");
} else {
pageFooter.append("\n\t\t <a href='" + this.pageUrl + "?page=1'><span class='pagenavnav2'>首页</span></a>");
pageFooter.append("\n\t\t <a href='" + this.pageUrl + "?page="+previousPage+"'><span class='pagenavnav2'>上一页</span></a>");
}
// 为尾页时处理
if (this.currentPage >= totalPages) {
pageFooter.append("\n\t\t <span class='pagenavnav1'>下一页</span>");
pageFooter.append("\n\t\t <span class='pagenavnav1'>末页</span>");
} else {
pageFooter.append("\n\t\t <a href='" + this.pageUrl
+ "?page="+nextPage+"'><span class='pagenavnav2'>下一页</span></a>");
pageFooter.append("\n\t\t <a href='" + this.pageUrl
+ "?page="+totalPages+"'><span class='pagenavnav2'>末页</span></a>");
}
// 任一页面跳转处理
pageFooter
.append("\n\t\t <span class='pagenavgo'><input class='pagenavbtngo' type='button' value='GO' "
+ style + " onclick=\"");
pageFooter.append("\n\t\t\t var __page_=parseInt(document.all.page.value);");
pageFooter.append("\n\t\t\t var __actionurl_=document.all.__actionURL.value;");
pageFooter.append("\n\t\t\t var __total_=document.all.__totalpage.value;");
pageFooter.append("\n\t\t\t __page_=(isNaN(__page_)?1:__page_);");
pageFooter.append("\n\t\t\t __page_=(__page_<1?1:__page_);");
pageFooter.append("\n\t\t\t __page_=(__page_>__total_?__total_:__page_);");
pageFooter.append("\n\t\t\t var __tourl_=__actionurl_+'?page='+__page_;");
pageFooter.append("\n\t\t\t window.location=__tourl_;");
pageFooter.append("\n\t\t \">");
pageFooter.append("\n\t\t <input type='text' name='page' value='" + this.currentPage
+ "' " + style + " class='pagenavpage'>页</span>");
pageFooter.append("\n\t\t <input type='hidden' name='__totalpage' value='"
+ totalPages + "' >");
pageFooter.append("\n\t\t <input type='hidden' name='__actionURL' value='"
+ this.pageUrl + "' >");
pageFooter.append("\n\t</form>");
pageFooter.append("\n</div>");
return pageFooter.toString();
}
}