Package com. shaccp. web. util;
Import java. util. List;
Public class PageBean {
/**
*
*
* @ Author ppy
* Total totalRecords records
* List stores paging data.
* PageNo current page
* PageSize page size
* Query stores the user query string
* PageAction: Servlet or Action (struts) on the Operation page)
* Method (the method corresponding to the Action in struts)
*
*
*/
Private int totalRecords;
Private List list;
Private int pageNo;
Private int pageSize;
Private String query;
Private String pageAction;
Private String method;
Public void setPageAction (String pageAction ){
This. pageAction = pageAction;
}
Public void setMethod (String method ){
This. method = method;
}
Public List getList (){
Return list;
}
Public void setList (List list ){
This. list = list;
}
Public int getPageNo (){
Return pageNo;
}
Public void setPageNo (int pageNo ){
This. pageNo = pageNo;
}
Public int getPageSize (){
Return pageSize;
}
Public void setPageSize (int pageSize ){
This. pageSize = pageSize;
}
Public int getTotalRecords (){
Return totalRecords;
}
Public void setTotalRecords (int totalRecords ){
This. totalRecords = totalRecords;
}
Public void setQuery (String query ){
This. query = query;
}
/**
* Return method for getting the total number of pages
* TotalRecords % pageSize = 0? (TotalRecords/pageSize) :( totalRecords/pageSize + 1)
*
* @ Return
*/
Public int getTotalPages (){
Return (totalRecords + pageSize-1)/pageSize;
}
/**
* Get the homepage
*
* @ Return
*/
Public int getTopPage (){
Return 1;
}
/**
* Get the previous page
*
* @ Return
*/
Public int getPreviousPageNo (){
If (pageNo <= 1)
Return 1;
Else
Return (pageNo-1 );
}
/**
* Get the next page
*
* @ Return
*/
Public int getNextPageNo (){
If (pageNo> = getTotalPages ()){
Return getTotalPages () = 0? 1: getTotalPages ();
} Else {
Return pageNo + 1;
}
}
/**
* Get the last page
*
* @ Return
*/
Public int getBottomPageNo (){
Return getTotalRecords () = 0? 1: getTotalPages ();
}
// Method 1 of page navigation
Public String getPageToolBar1 (){
String str = "";
Str + = "<a href = '" + pageAction + "? Method = "+ method +" & userQuery ="
+ Query + "& pageNo =" + getPreviousPageNo () + "& pageSize ="
+ PageSize + "'> previous page </a> ";
Str + = "<a href = '" + pageAction + "? Method = "+ method +" & userQuery ="
+ Query + "& pageNo =" + getNextPageNo () + "& pageSize ="
+ PageSize + "'> next page </a> ";
Return str;
}
// Link method 2 of page navigation
Public String getPageToolBar2 (){
String str = "";
Int pageSplit = (pageNo/5) * 5;
For (int I = pageSplit-1; I <(pageSplit + 6); I ++ ){
If (I <= 0 ){
} Else if (pageNo = I ){
Str + = I + "";
} Else if (I> getTotalPages ()){
} Else {
Str + = "<a href = '" + pageAction + "? Method = "+ method
+ "& UserQuery =" + query + "& pageNo =" + I + "& pageSize ="
+ PageSize + "'>" + I + "</a>" + "";
}
}
Return str;
}
}