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

📄 paginationtagspeedstyletwo.java

📁 羽量级数据持久层开发框架
💻 JAVA
字号:
/**
 *
 */



package org.speedframework.tag;

//~--- non-JDK imports --------------------------------------------------------

import org.apache.log4j.Logger;

import org.speedframework.entity.Pagination;

//~--- JDK imports ------------------------------------------------------------

import java.io.IOException;

import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

/**
 * <p/>
 * Title: SpeedFrameworkWork锟街久诧拷锟??
 * </p>
 * <p/>
 * <p/>
 * Description: 锟斤拷锟节凤拷页锟斤拷签??
 * </p>
 * <p/>
 * <p/>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p/>
 * <p/>
 * Company: SpeedFrameworkWork
 * </p>
 *
 * @author 锟斤拷志?? 锟界话??13824431576
 * @version 1.1beta
 */
public class PaginationTagSpeedStyleTwo extends TagSupport
 {

    /** 属性描述信息 */
    private static final Logger log = Logger.getLogger(PaginationTagSpeedStyleTwo.class);

    /** 属性描述信息 */
    private static final long serialVersionUID = 1673491971683216709L;

    /** 属性描述信息 */
    private String formName = null;

    /** 属性描述信息 */
    private String name = null;

    /** 属性描述信息 */
    private String parameter = null;

    /** 属性描述信息 */
    private String path = null;

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param path
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param parameter
     */
    public void setParameter(String parameter) {
        this.parameter = parameter;
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param formName
     */
    public void setFormName(String formName) {
        this.formName = formName;
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @return
     *
     * @throws JspException
     */
    public int doStartTag() throws JspException {
        Pagination pagination = null;

        if (this.path == null) {
            throw new NullPointerException("path is null");
        }

        if (this.name == null) {
            this.name = "pagination";
        }

        if (this.parameter == null) {
            this.parameter = "page";
        }

        pagination = (Pagination) pageContext.getRequest().getAttribute(name);

        if (pagination == null) {
            throw new NullPointerException(name + "is null in request");
        }

        try {
            JspWriter out = pageContext.getOut();

            out.print("<table border=0 cellpadding=0 width=10% cellspacing=0>");
            out.print("<tr align=center valign=top>");
            out.print("<td>");

            String contextPath = encodeURL(this.path, this.parameter);

            if ((this.formName != null) && (this.formName.length() > 0)) {
                this.getPreviousPageWriter(pagination, out, contextPath);
                out.print("</td>");
                this.getCurrPageWriter(pagination, out, contextPath);
                out.print("</td>");
                out.print("<td>");
                this.getNextPageWriter(pagination, out, contextPath);
            } else {
                if (pagination.isHasPreviousPage()) {
                    out.println("<a class=\"pagination\" href=\"" + contextPath + "1\" title=\"First\">First</a>");
                    out.println("<a class=\"pagination\" href=\"" + contextPath + pagination.getPreviousPage()
                                + "\" title=\"Previous\">Previous</a>");
                } else {
                    out.println("<span title=\"First\">First</span>");
                    out.println("<span title=\"Previous\">Previous</span>");
                }

                if (pagination.isHasNextPage()) {
                    out.println("<a class=\"pagination\" href=\"" + contextPath + pagination.getNextPage()
                                + "\" title=\"Next\">Next</a>");
                    out.println("<a class=\"pagination\" href=\"" + contextPath + pagination.getTotalPage()
                                + "\" title=\"Last\">Last</a>");
                } else {
                    out.println("<span title=\"Next\">Next</span>");
                    out.println("<span title=\"Last\">Last</span>");
                }
            }

            out.print("</td>");
            out.print("</tr>");
            out.print("</table>");
            out.println("&nbsp;");
            out.println("Total " + pagination.getTotalCount() + "");
            out.print("&nbsp;");
            out.println("PageOf " + pagination.getCurrPage() + "");
            out.print("&nbsp;");

            /* 锟斤拷锟斤拷CSS锟斤拷锟斤拷 */
            createCSS(out);

            if ((this.formName != null) && (this.formName.length() > 0)) {

                /* 锟斤拷锟斤拷js锟斤拷锟斤拷 */
                createJS(out, contextPath, pagination.getTotalPage());
            } else {
                createNoFormJS(out, this.path, pagination.getTotalPage());
            }

            out.println();
        } catch (Exception e) {
            throw new JspException(e);
        }

        return SKIP_BODY;
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param pagination
     * @param out
     * @param contextPath
     *
     * @throws IOException
     */
    private void getNextPageWriter(Pagination pagination, JspWriter out, String contextPath) throws IOException {
        if (pagination.isHasNextPage()) {
            out.println(
                "<a class=\"pagination\" href=\"" + contextPath + pagination.getNextPage()
                + "\" onclick=\"paginationSubmit('" + pagination.getNextPage() + "');return false;\"  title=\"Next\">"
                + "<img src=\"pageimage/speed/currE.gif\"  border=\"0\" /><img src=\"pageimage/speed/d.gif\" border=\"0\" /><img src=\"pageimage/speed/next.jpg\" border=\"0\" /></br>"
                + "Next</a>");
        } else {
            out.println(
                "<img src=\"pageimage/speed/currE.gif\"  border=\"0\" /><img src=\"pageimage/speed/d.gif\" border=\"0\" /><img src=\"pageimage/speed/next.jpg\" border=\"0\" /></br>Next");
        }
    }

    /**
     * 锟斤拷锟斤拷式锟斤拷??
     *
     * @param pagination
     * @param out
     * @param contextPath
     * @throws IOException
     */
    private void getCurrPageWriter(Pagination pagination, JspWriter out, String contextPath) throws IOException {
        int beginPage = ((pagination.getCurrPage() - 3) < 1)
                        ? 1
                        : (pagination.getCurrPage() - 3);

        for (int i = beginPage, j = 0; (i <= pagination.getTotalPage()) && (j < 6); i++, j++) {
            out.print("<td>");

            if (i != pagination.getCurrPage()) {
                out.println("<a href=\"" + contextPath + i + "\" onclick=\"paginationSubmit('" + i
                            + "');return false;\">" + "<img src=\"pageimage/speed/e.gif\"  border=\"0\" /></br>" + i
                            + "</a>");
            } else {
                out.println("<img src=\"pageimage/speed/currE.gif\"  border=\"0\" /></br>" + i);
            }

            out.print("</td>");
        }
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param pagination
     * @param out
     * @param contextPath
     *
     * @throws IOException
     */
    private void getPreviousPageWriter(Pagination pagination, JspWriter out, String contextPath) throws IOException {
        if (pagination.isHasPreviousPage()) {
            out.println(
                "<a class=\"pagination\" href=\"" + contextPath + pagination.getPreviousPage()
                + "\" onclick=\"paginationSubmit('" + pagination.getPreviousPage()
                + "');return false;\" title=\"Previous\">"
                + "<img src=\"pageimage/speed/pre.jpg\"  border=\"0\" /><img src=\"pageimage/speed/s.gif\"  border=\"0\" /><img src=\"pageimage/speed/p.gif\"  border=\"0\" /></br>"
                + "Previous</a>");
        } else {
            out.println(
                "<img src=\"pageimage/speed/pre.jpg\"  border=\"0\" /><img src=\"pageimage/speed/s.gif\"  border=\"0\" /><img src=\"pageimage/speed/p.gif\"  border=\"0\" /></br>Previous");
        }
    }

    /*
     *  (non-Javadoc)
     *
     *  @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
     */

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @return
     *
     * @throws JspException
     */
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    /**
     * 锟侥憋拷URL使锟斤拷锟杰凤拷锟绞碉拷action锟斤拷servlet锟斤拷去
     *
     * @param href     锟斤拷页锟芥传4锟斤拷href
     * @param param
     * @return
     * @author
     */
    private final String encodeURL(String href, String param) {
        StringBuffer       buffer  = new StringBuffer(100);
        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();

        buffer.append(request.getContextPath() + "/" + href);

        int question = href.indexOf("?");

        if (question > 0) {
            buffer.append("&" + param + "=");
        } else {
            buffer.append("?" + param + "=");
        }

        return buffer.toString();
    }

    /**
     * 锟斤拷锟斤拷js锟斤拷锟斤拷锟斤拷锟斤拷峤籪orm锟斤拷锟斤拷js锟结交
     *
     * @param out
     * @param contextPath
     * @param totalPage
     * @throws Exception
     * @author
     */
    private final void createJS(JspWriter out, String contextPath, int totalPage) throws Exception {
        out.println("<script language=\"javascript\">");
        out.println("function paginationSubmit(pageNum_) { ");
        out.println("  document." + formName + ".action=\'" + contextPath + "\' + pageNum_ + \'\';");
        out.println("  document." + formName + ".submit();");
        out.println("}");

        /* 锟斤拷转锟斤拷锟斤拷 */
        HttpServletRequest request  = (HttpServletRequest) this.pageContext.getRequest();
        String             contPath = request.getContextPath() + "/" + this.path;

        out.println("function paginationGoto() { ");
        out.println("  if(!controlNotNull(document.all." + this.parameter + ", '锟斤拷转页锟斤拷')) {");
        out.println("    return;");
        out.println("  }");
        out.println("  ");
        out.println("  if(!controlIsInt(document.all." + this.parameter + ", '锟斤拷转页锟斤拷')) {");
        out.println("    return;");
        out.println("  }");
        out.println("  ");
        out.println("  pageNum_ = document.all." + this.parameter + ".value");
        out.println("  if(pageNum_ > 0 && pageNum_ <= " + totalPage + ") {");
        out.println("    document." + formName + ".action=\'" + contPath + "&" + this.parameter
                    + "=\' + pageNum_ + \'\';");
        out.println("    document." + formName + ".submit();");
        out.println("  } else { ");
        out.println("    alert(\"锟斤拷锟斤拷锟斤拷锟揭筹拷锟斤拷围\");");
        out.println("  }");
        out.println("}");
        out.println("</script>");
        out.println();
    }

    /**
     * 锟斤拷锟斤拷没锟斤拷form时锟斤拷js
     *
     * @param out
     * @thros Exception
     * @author
     * @param href
     * @param totalPage
     *
     * @throws Exception
     */
    private final void createNoFormJS(JspWriter out, String href, int totalPage) throws Exception {
        HttpServletRequest request  = (HttpServletRequest) this.pageContext.getRequest();
        String             contPath = request.getContextPath() + "/" + href;

        out.println("<script language=\"javascript\">");
        out.println("function paginationGoto() { ");
        out.println("  if(!controlNotNull(document.all." + this.parameter + ", '锟斤拷转页锟斤拷')) {");
        out.println("    return;");
        out.println("  }");
        out.println("  ");
        out.println("  if(!controlIsInt(document.all." + this.parameter + ", '锟斤拷转页锟斤拷')) {");
        out.println("    return;");
        out.println("  }");
        out.println("  ");
        out.println("  pageNum_ = document.all." + this.parameter + ".value");
        out.println("  if(pageNum_ > 0 && pageNum_ <= " + totalPage + ") {");
        out.println("    document.location.href=\'" + contPath + "&" + this.parameter + "=\' + pageNum_ + \'\';");
        out.println("  } else { ");
        out.println("    alert(\"锟斤拷锟斤拷锟斤拷锟揭筹拷锟斤拷围\");");
        out.println("  }");
        out.println("}");
        out.println("</script>");
        out.println();
    }

    /**
     * 锟斤拷锟斤拷css锟斤拷锟斤拷
     *
     * @param out
     * @throws Exception
     * @author
     */
    private final void createCSS(JspWriter out) throws Exception {
        out.println("<style type=\"text/css\">");
        out.println("a.pagination:visited { text-decoration: underline; color: #808080; } ");    // #CCCCFF

        // #c0c0c0
        out.println("a.pagination:link { text-decoration: underline; color: blue; } ");
        out.println("a.pagination:hover { text-decoration: none; color: #009933; } ");
        out.println("a.pagination:active { text-decoration: none; color: orangered; } ");
        out.println("</style>");
    }
}

⌨️ 快捷键说明

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