/**
*
*/
package com.smis.jspdev.util.page;
import java.util.List;
import com.smis.jspdev.util.SystemAttributes;
import com.smis.util.web.WebWorkBaseAction;
/**
* @author larry (yun_li@asdc.com.cn)
*
*/
public class PaginationAction extends WebWorkBaseAction {
/**
*
*/
/** member: serialVersionUID field type: long */
private static final long serialVersionUID = 1L;
/** member: page field type: Page */
private Page page = new Page();
/** member: gotoPageButton field type: PageComponentBean */
private PageComponentBean gotoPageButton = new PageComponentBean(
"comm_page_gtp", "comm_page_gtp", "", "");
/** member: firstPageLabel field type: String */
private String firstPageLabel = "[首页]";
/** member: lastPageLabel field type: String */
private String lastPageLabel = "[尾页]";
/** member: prevPageLabel field type: String */
private String prevPageLabel = "[上一页]";
/** member: nextPageLabel field type: String */
private String nextPageLabel = "[下一页]";
/** member: firstPageLabel_g field type: String */
private String firstPageLabel_g = "[首页]";
/** member: lastPageLabel_g field type: String */
private String lastPageLabel_g = "[尾页]";
/** member: prevPageLabel_g field type: String */
private String prevPageLabel_g = "[上一页]";
/** member: nextPageLabel_g field type: String */
private String nextPageLabel_g = "[下一页]";
/** member: hiddenIndexId field type: String */
private String hiddenIndexId = "indexid";
/** member: hiddenIndexName field type: String */
private String hiddenIndexName = "page.currentPageNo";
private String page_query_actionName = "";
/**
* method: getPage
*
* @return return type: Page
*/
public Page getPage() {
return page;
}
/**
* method: setPage
*
* @param page
* return type: void
*/
public void setPage(Page page) {
this.page = page;
}
/**
* 默认的js输出 method: outPutStatndardJs
*
* @return 输出时注意escape为false return type: String
*/
public String outPutStatndardJs() {
return outPutStatndardJs("forms[0]");
}
public static void main(String args[]) {
PaginationAction pageaction = new PaginationAction();
Page page = new Page();
page.setCurrentPageNo(1);
page = PageFactory.createPage(page, 25);
pageaction.setPage(page);
System.out
.println(pageaction.outPutWapStandardNavBar(2, "list.action"));
}
/**
* 默认的js输出,可自定义formname method: outPutStatndardJs
*
* @param formName
* @return 输出时注意escape为false return type: String
*/
public String outPutStatndardJs(String formName) {
StringBuffer buf = new StringBuffer("\n");
buf.append("function comm_page_pageButton(button){\n");
buf.append(" var index=" + page.getCurrentPageNo() + ";\n");
buf.append(" var pages=" + page.getTotalPageNo() + ";\n");
buf.append(" //" + firstPageLabel + "按下\n");
buf.append(" if(button==1){\n");
buf.append(" index=1;\n");
buf.append(" }\n");
buf.append(" //" + prevPageLabel + "\n");
buf.append(" if(button==2){\n");
buf.append(" index--;\n");
buf.append(" }\n");
buf.append(" //" + nextPageLabel + "\n");
buf.append(" if(button==3){\n");
buf.append(" index++;\n");
buf.append(" }\n");
buf.append(" //" + lastPageLabel + "\n");
buf.append(" if(button==4){\n");
buf.append(" index=pages;\n");
buf.append(" }\n");
buf.append(" comm_page_gotoPage(index);\n");
buf.append("}\n");
buf.append("\n");
buf.append("function comm_page_gotoPage(index){\n");
buf.append(" if(isNaN(index)){\n");
buf.append(" index=1;\n");
buf.append(" }\n");
buf.append(" index = parseInt(index)\n");
buf.append(" if(index<1){\n");
buf.append(" index=1;\n");
buf.append(" }\n");
buf.append(" document." + formName + ".reset();\n");
buf.append(" document.getElementById('" + hiddenIndexId
+ "').value=index;\n");
buf.append(" document." + formName + ".submit();\n");
buf.append("}\n");
buf.append("\n");
System.out.println(buf.toString());
return buf.toString();
}
/**
* 输出默认的导航条,可与默认的js输出相匹配
*
* @param cols
* @return
*/
public String outPutStandardNavBar(int cols) {
return outPutStandardNavBar(cols, false);
}
/**
* 输出默认的导航条,可与默认的js输出相匹配
*
* @param cols
* @return
*/
public String outPutStandardNavBar(int cols, boolean fill) {
return outPutNavBar(cols, "comm_page_pageButton(1)",
"comm_page_pageButton(4)", "comm_page_pageButton(2)",
"comm_page_pageButton(3)", "comm_page_gotoPage("
+ gotoPageButton.getId() + ".value)", fill);
}
/**
* 这个方法输出翻页使用的导航栏
*
* @param cols
* 需要分页的table的colspan
* @param firstPMethod
* 按下‘首页’按钮以后运行的js方法
* @param lastPMethod
* 按下‘末页’按钮以后运行的js方法
* @param prevPMethod
* 按下‘上一页’按钮以后运行的js方法
* @param nextPMethod
* 按下‘下一页’按钮以后运行的js方法
* @param gotoMethod
* 按下‘转’按钮以后运行的js方法
* @return 导航栏字符串 输出时注意escape为false
*/
public String outPutNavBar(int cols, String firstPMethod,
String lastPMethod, String prevPMethod, String nextPMethod,
String gotoMethod, boolean fill) {
int index = page.getCurrentPageNo();
int pages = page.getTotalPageNo();
boolean firstPage = false;
boolean lastPage = false;
String pageMarks = " <B><font color = red>" + index + "/"
+ pages + " total:" + page.getTotalNo() + " </font></B>";
StringBuffer navBar = new StringBuffer("");
if (fill) {
int totalRecord = page.getCurrentPageRecords();
int max = page.getMaxNo();
int gap = max - totalRecord;
if (gap < max) {
for (int i = 0; i < gap; i++) {
navBar.append("<tr bgcolor=\"#FFFFFF\">");
for (int j = 0; j < cols; j++) {
navBar.append("<td> </td>");
}
navBar.append("</tr>");
}
}
}
navBar.append("<tr height=22 algin=\"right\">");
navBar.append("<td colspan=\"" + cols + "\">");
if (index == 1) {
firstPage = true;
}
if (index == pages || pages == 0) {
lastPage = true;
}
if ((firstPage && lastPage) || pages == 0) {// 只有一页或者没有数据的情况
navBar.append("" + firstPageLabel_g + " " + prevPageLabel_g
+ " " + nextPageLabel_g + " " + lastPageLabel_g
+ " ");
navBar.append("<input id='" + gotoPageButton.getId()
+ "' type=text size=3 maxlength=4 value='");
navBar.append(index);
navBar.append("'>");
navBar.append("<input type=button value='转' onclick='" + gotoMethod
+ "' disabled>");
} else if (firstPage) {// 第一页的情况
navBar.append("" + firstPageLabel_g + " " + prevPageLabel_g
+ " ");
navBar.append("<a href='javascript:" + nextPMethod
+ "' border='0'>" + nextPageLabel + "</a> ");
navBar.append("<a href='javascript:" + lastPMethod
+ "' border='0'>" + lastPageLabel + "</a> ");
navBar.append("<input id='" + gotoPageButton.getId()
+ "' type=text size=3 maxlength=4 value='");
navBar.append(index);
navBar.append("'><input type=button value='转' onclick='"
+ gotoMethod + "'>");
} else if (lastPage) {// 尾页的情况
navBar.append("<a href='javascript:" + firstPMethod
+ "' border='0'>" + firstPageLabel + "</a> ");
navBar.append("<a href='javascript:" + prevPMethod
+ "' border='0'>" + prevPageLabel + "</a> ");
navBar.append("" + nextPageLabel_g + " " + lastPageLabel_g
+ " 
评论0
最新资源