📄 basepagertag.java
字号:
package com.pegasus.framework.component.taglib.html.pager;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.jsp.JspException;
import org.apache.struts.Globals;
import com.pegasus.framework.component.taglib.util.BaseBodySupportTag;
import com.pegasus.framework.component.taglib.util.JspResponseWriter;
public abstract class BasePagerTag extends BaseBodySupportTag {
/** The logger. */
//private Logger logger = LogManager.getLogger(BasePagerTag.class);
/** The Constant DEFAULT_INPUT_SIZE. */
protected static final int DEFAULT_INPUT_SIZE = 3;
/** The Constant DEFAULT_INPUT_MAXLENGTH. */
protected static final int DEFAULT_INPUT_MAXLENGTH = 5;
/** The Constant DEFAULT_PAGE_NUMBER. */
protected static final int DEFAULT_PAGE_NUMBER = 10;
/** The Constant DEFAULT_FETCH_SIZE. */
protected static final int DEFAULT_FETCH_SIZE = 5;
/** The Constant PAGE_TYPE_LINK. */
protected static final String PAGE_TYPE_LINK = "link";
/** The Constant PAGE_TYPE_IMG. */
protected static final String PAGE_TYPE_IMG = "img";
/** The Constant PAGE_TYPE_BTN. */
protected static final String PAGE_TYPE_BTN = "btn";
/** The Constant DEFAULT_PAGE_NO_PROPERTY. */
protected static final String DEFAULT_PAGE_NO_PROPERTY = "pageAgent.pageNo";
/** The Constant DEFAULT_FETCH_SIZE_PROPERTY. */
protected static final String DEFAULT_FETCH_SIZE_PROPERTY = "pageAgent.fetchSize";
/** The Constant DEFAULT_TOTAL_OBJECT_PROPERTY. */
protected static final String DEFAULT_TOTAL_OBJECT_PROPERTY = "pageAgent.totalObjectCount";
/** The Constant DEFAULT_TOTAL_PAGE_COUNT_PROPERTY. */
protected static final String DEFAULT_TOTAL_PAGE_COUNT_PROPERTY = "pageAgent.totalPageCount";
/** The name. */
protected String name = null;
/** The page no property. */
protected String pageNoProperty = DEFAULT_PAGE_NO_PROPERTY;
/** The fetch size property. */
protected String fetchSizeProperty = DEFAULT_FETCH_SIZE_PROPERTY;
/** The total object count property. */
protected String totalObjectCountProperty = DEFAULT_TOTAL_OBJECT_PROPERTY;
/** The total page count property. */
protected String totalPageCountProperty = DEFAULT_TOTAL_PAGE_COUNT_PROPERTY;
/** The scope. */
protected String scope = null;
/** The table style class. */
protected String tableStyleClass = null;
/** The td style class. */
protected String tdStyleClass = null;
/** The input style class. */
protected String inputStyleClass = null;
/** The btn style class. */
protected String btnStyleClass = null;
/** The table style. */
protected String tableStyle = null;
/** The td style. */
protected String tdStyle = null;
/** The input style. */
protected String inputStyle = null;
/** The btn style. */
protected String btnStyle = null;
/** The page type. */
protected String pageType = PAGE_TYPE_LINK;
/** The use resource. */
protected boolean useResource = false;
/** The bundle. */
protected String bundle = Globals.MESSAGES_KEY;
/** The url. */
protected String url = null;
/** The first img. */
protected String firstImg = null;
/** The pre img. */
protected String preImg = null;
/** The next img. */
protected String nextImg = null;
/** The last img. */
protected String lastImg = null;
/** The first source. */
protected String firstSource = "First";
/** The pre source. */
protected String preSource = "Previous";
/** The next source. */
protected String nextSource = "Next";
/** The last source. */
protected String lastSource = "Last";
/** The separator. */
protected String separator = " ";
/** The show page number. */
protected boolean showPageNumber = false;
/** The max page number. */
protected int maxPageNumber = DEFAULT_PAGE_NUMBER;
/** The total object title. */
protected String totalObjectTitle = "Total object";
/** The fetch size title. */
protected String fetchSizeTitle = "Page Size";
/** The writer. */
protected JspResponseWriter writer = new JspResponseWriter();
/** The page no. */
protected int pageNo = 1;
/** The fetch size. */
protected int fetchSize = DEFAULT_FETCH_SIZE;
/** The total object count. */
protected int totalObjectCount = 0;
/** The total page count. */
protected int totalPageCount = 0;
/** The fetch size vector. */
protected static Vector fetchSizeVector = null;
static {
fetchSizeVector = new Vector();
fetchSizeVector.add("5");
fetchSizeVector.add("10");
fetchSizeVector.add("20");
fetchSizeVector.add("30");
fetchSizeVector.add("40");
fetchSizeVector.add("50");
fetchSizeVector.add("100");
fetchSizeVector.add("200");
}
/**
* Calculate page.计算总页数
*
* @return the int
*/
private int calculatePage() {
int result = 0;
if (totalObjectCount == 0) {
result = 0;
}
else {
result = totalObjectCount / fetchSize;
int d = totalObjectCount % fetchSize;
if (d > 0)
result++;
}
return result;
}
/**
* Do start tag.
*
* @return the int
*
* @throws JspException the jsp exception
*/
public int doStartTag() throws JspException {
// logger.info("doStartTag");
setPageNo(lookupProperty(name, pageNoProperty));
setFetchSize(lookupProperty(name, fetchSizeProperty));
setTotalObjectCount(lookupProperty(name, totalObjectCountProperty));
setTotalPageCount(lookupProperty(name, totalPageCountProperty));
//logger.info("pageSize : " + pageNo);
//logger.info("fecthSize : " + fetchSize);
//logger.info("totalObjectCount : " + totalObjectCount);
//logger.info("totalPageCount : " + totalPageCount);
// 初始化Pager参数
initPager();
// 组成javascript
prepareJs();
writer.textLineBreak();
// 组成html
prepareHtml();
//logger.info(writer.getBuffer().toString());
try {
pageContext.getOut().println(writer.getBuffer().toString());
}
catch (IOException e) {
throw new JspException(e);
}
return (EVAL_PAGE);
}
/**
* Prepare html.组成HTML
*/
protected abstract void prepareHtml() throws JspException;
/**
* Prepare js.组成javascript
*/
protected abstract void prepareJs() throws JspException;
/**
* Inits the pager.初始化分页标签参数
*/
protected abstract void initPager();
/**
* @return
* @throws JspException
*/
public int doEndTag() throws JspException {
writer = new JspResponseWriter();
return EVAL_PAGE;
}
/**
*
*/
public void release() {
// logger.info("release");
reset();
super.release();
}
/**
* Reset.
*/
private void reset() {
name = null;
pageNoProperty = DEFAULT_PAGE_NO_PROPERTY;
fetchSizeProperty = DEFAULT_FETCH_SIZE_PROPERTY;
totalObjectCountProperty = DEFAULT_TOTAL_OBJECT_PROPERTY;
totalPageCountProperty = DEFAULT_TOTAL_PAGE_COUNT_PROPERTY;
scope = null;
tableStyleClass = null;
tdStyleClass = null;
inputStyleClass = null;
btnStyleClass = null;
tableStyle = null;
tdStyle = null;
inputStyle = null;
btnStyle = null;
tableStyle = null;
inputStyle = null;
btnStyle = null;
pageType = PAGE_TYPE_LINK;
useResource = false;
bundle = Globals.MESSAGES_KEY;
url = null;
firstImg = null;
preImg = null;
nextImg = null;
lastImg = null;
firstSource = "First";
preSource = "Previous";
nextSource = "Next";
lastSource = "Last";
separator = " ";
showPageNumber = false;
maxPageNumber = DEFAULT_PAGE_NUMBER;
totalObjectTitle = "Total object";
fetchSizeTitle = "Page Size";
writer = null;
pageNo = 1;
fetchSize = DEFAULT_FETCH_SIZE;
totalObjectCount = 0;
totalPageCount = 0;
}
/**
* Sets the total object count.
*
* @param totalObjectCount the new total object count
*/
public void setTotalObjectCount(String totalObjectCount) {
if (totalObjectCount == null || totalObjectCount.length() <= 0) {
this.totalObjectCount = 0;
}
else {
this.totalObjectCount = new Integer(totalObjectCount).intValue();
}
}
/**
* Sets the page no.
*
* @param pageNo the new page no
*/
public void setPageNo(String pageNo) {
if (pageNo == null || pageNo.length() <= 0) {
this.pageNo = 1;
}
else {
this.pageNo = new Integer(pageNo).intValue();
}
}
/**
* Sets the fetch size.
*
* @param fetchSize the new fetch size
*/
public void setFetchSize(String fetchSize) {
if (fetchSize == null || fetchSize.length() <= 0) {
this.fetchSize = DEFAULT_FETCH_SIZE;
}
else {
this.fetchSize = new Integer(fetchSize).intValue();
}
}
/**
* Sets the total page count.
*
* @param totalPageCount the new total page count
*/
public void setTotalPageCount(String totalPageCount) {
if (totalPageCount == null || totalPageCount.length() <= 0) {
this.totalPageCount = calculatePage();
}
else {
this.totalPageCount = new Integer(totalPageCount).intValue();
}
}
/**
* Gets the btn style.
*
* @return Returns the btnStyle.
*/
public String getBtnStyle() {
return btnStyle;
}
/**
* Sets the btn style.
*
* @param btnStyle The btnStyle to set.
*/
public void setBtnStyle(String btnStyle) {
this.btnStyle = btnStyle;
}
/**
* Gets the bundle.
*
* @return Returns the bundle.
*/
public String getBundle() {
return bundle;
}
/**
* Sets the bundle.
*
* @param bundle The bundle to set.
*/
public void setBundle(String bundle) {
this.bundle = bundle;
}
/**
* Gets the fetch size property.
*
* @return Returns the fetchSizeProperty.
*/
public String getFetchSizeProperty() {
return fetchSizeProperty;
}
/**
* Sets the fetch size property.
*
* @param fetchSizeProperty The fetchSizeProperty to set.
*/
public void setFetchSizeProperty(String fetchSizeProperty) {
this.fetchSizeProperty = fetchSizeProperty;
}
/**
* Gets the first img.
*
* @return Returns the firstImg.
*/
public String getFirstImg() {
return firstImg;
}
/**
* Sets the first img.
*
* @param firstImg The firstImg to set.
*/
public void setFirstImg(String firstImg) {
this.firstImg = firstImg;
}
/**
* Gets the first source.
*
* @return Returns the firstSource.
*/
public String getFirstSource() {
return firstSource;
}
/**
* Sets the first source.
*
* @param firstSource The firstSource to set.
*/
public void setFirstSource(String firstSource) {
this.firstSource = firstSource;
}
/**
* Gets the input style.
*
* @return Returns the inputStyle.
*/
public String getInputStyle() {
return inputStyle;
}
/**
* Sets the input style.
*
* @param inputStyle The inputStyle to set.
*/
public void setInputStyle(String inputStyle) {
this.inputStyle = inputStyle;
}
/**
* Gets the last img.
*
* @return Returns the lastImg.
*/
public String getLastImg() {
return lastImg;
}
/**
* Sets the last img.
*
* @param lastImg The lastImg to set.
*/
public void setLastImg(String lastImg) {
this.lastImg = lastImg;
}
/**
* Gets the last source.
*
* @return Returns the lastSource.
*/
public String getLastSource() {
return lastSource;
}
/**
* Sets the last source.
*
* @param lastSource The lastSource to set.
*/
public void setLastSource(String lastSource) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -