⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagetag.java

📁 OA典型例子
💻 JAVA
字号:
package com.sure.taglibs.page;
/**
 *@author     Mengzy
 *@date       2002-5-12
 */
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.BodyContent;

import java.io.IOException;
import java.util.*;
import com.sure.businessmodel.Page;

public class PageTag extends BodyTagSupport {
    private String sourceId = "";
    private String sourceScope = "";
    private String nextLabel = "下一页>>";
    private String previousLabel = "<<上一页";
    private String totalRecordsLabel = "?条记录";
    private String totalLabel = "共?页&nbsp;";
    private String currentLabel = "当前第?页&nbsp;";
    private String form = "thisForm";
    private StringBuffer html = null;
    private Page targetObject = null;
    private final String jumpTo = "\n<script language=\"javascript\">"  +
                            "\n\tfunction jumpto(start, form){"  +
                            "\n\t\tvar oForm = document.all(form);" +
                            "\n\t\tif(oForm==null) return;" +
                            "\n\t\toForm.start.value=start;" +
                            "\n\t\toForm.submit();" +
                            "\n\t}\n" +
                            "\nfunction jumptoPage(pageSize, form){" +
                            "\n\tif(event.keyCode != 13)	return;" +
                            "\n\t\tvar pageValue = parseInt(event.srcElement.value);" +
                            "\n\t\tif(isNaN(pageValue) || pageValue<=0) {" +
                            "\n\t\t\tevent.srcElement.value=\"\";" +
                            "\n\t\t\treturn;" +
                            "\n\t\t}" +
                            "\n\t\tjumpto((pageValue-1)*pageSize + 1, form);" +
                            "\n\t}" +
                            "\n</script>";

    public int doStartTag() throws JspTagException {
	targetObject = null;
	if (sourceScope.equals("request")) {
	    targetObject = (Page) pageContext.getRequest().getAttribute(sourceId);
	} else if (sourceScope.equals("session")) {
	    targetObject = (Page) pageContext.getSession().getAttribute(sourceId);
	} else if (sourceScope.equals("page")) {
	    targetObject = (Page) pageContext.getAttribute(sourceId);
	}
	if (targetObject == null) {
	    throw new JspTagException("PageTag: Target Item " + sourceId + " not found in " + sourceScope + " scope.");
	}
	return EVAL_BODY_BUFFERED;
    }

    public int doEndTag() throws JspTagException {
        try {
            html = new StringBuffer();

            if(targetObject.hasPreviousPage()) {
                html.append(appendPageLabel(targetObject.getStartOfPreviousPage(), previousLabel));
            }
            if(targetObject.hasNextPage()) {
                html.append(appendPageLabel(targetObject.getStartOfNextPage(), nextLabel));
            }

            currentLabel = (appendReplace(currentLabel, "&nbsp;<input type=\"text\" size=\"5\" maxlength=\"5\" value=\"?\" style=\"text-align:right\" onkeyup=\"jumptoPage(" + targetObject.getPageSize() +",'" + form + "')\">")).toString();
            html.append(appendReplace(currentLabel,
                    (new Integer(targetObject.getPageNumber())).toString()));
            html.append(appendReplace(totalLabel,
                    (new Integer(targetObject.getPageCount())).toString()));
            html.append(appendReplace(totalRecordsLabel,
                    (new Integer(targetObject.getTotalRecords())).toString()));

            pageContext.getOut().print((html.append(jumpTo)).toString());
            return EVAL_PAGE;
        }
        catch (IOException e) {
            throw new JspTagException("PageTag: " + e.getMessage());
        }
    }
    public void setCurrentLabel(String currentLabel) {
        this.currentLabel = currentLabel;
    }
    public void setNextLabel(String nextLabel) {
        this.nextLabel = nextLabel;
    }
    public void setId(String id) {
        this.sourceId = id;
    }
    public void setPreviousLabel(String previousLabel) {
        this.previousLabel = previousLabel;
    }
    public void setTotalLabel(String totalLabel) {
        this.totalLabel = totalLabel;
    }
    public void setScope(String sourceScope) {
        this.sourceScope = sourceScope;
    }

    public void setForm(String form) {
        this.form = form;
    }
    private String appendPageLabel(int page, String content) {
        return "<a href=\"javascript:jumpto(" + page + ",'" + form + "')\">" + content + "</a>&nbsp;";
    }

    private StringBuffer appendReplace(String source, String info){
        int index = source.indexOf("?");
        return (new StringBuffer(source)).replace(index, index+1, info);
    }
  public void setTotalRecordsLabel(String totalRecordsLabel) {
    this.totalRecordsLabel = totalRecordsLabel;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -