mpagetag.java

来自「一个非常好的FRAMWRK!是一个外国组织做的!不!」· Java 代码 · 共 140 行

JAVA
140
字号
/**
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

package com.jdon.strutsutil.taglib;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.html.LinkTag;

import com.jdon.strutsutil.FormBeanUtil;
import com.jdon.strutsutil.ModelListForm;
import com.jdon.util.Debug;
/**
 * 类似Html:link
 *
 * <p>Copyright: Jdon.com Copyright (c) 2003</p>
 * <p></p>
 * @author banq
 * @version 1.0
 */
public class MPageTag extends LinkTag {

  private final static String module = MPageTag.class.getName();

  public final static String URLNAME = "URL";
  public final static String COUNT = "COUNT";
  public final static String START = "START";
  public final static String ALLCOUNT = "ALLCOUNT";
  public final static String NEXTPAGE = "NEXTPAGE";
  public final static String DISP = "DISP";

  private String actionFormName;



  // --------------------------------------------------------- Public Methods

  /**
   * Render the beginning of the hyperlink.
   *
   * @exception JspException if a JSP exception has occurred
   */
  public int doStartTag() throws JspException {

    // Generate the URL to be encoded
    ModuleConfig config = (ModuleConfig) pageContext.getRequest()
        .getAttribute(org.apache.struts.Globals.MODULE_KEY);

    HttpServletRequest request =
        (HttpServletRequest) pageContext.getRequest();
    String pageUrl = calculateURL();
    StringBuffer url = new StringBuffer(pageUrl);
    if (pageUrl.indexOf("?") < 0)
      url.append("?");
    else
      url.append("&");



    ModelListForm form = null;
    try {
      form = (ModelListForm)FormBeanUtil.lookupActionForm((HttpServletRequest)pageContext.getRequest(), actionFormName);
      if (form == null)  throw new Exception();
    } catch (Exception e) {
      Debug.logError("not found actionFormName value: " + actionFormName, module);
      throw new JspException(" not found " + actionFormName);
    }

    int start = form.getStart();
    int allCount = form.getAllCount();
    int count = form.getCount();
    url.append("count=").append(count);

    String nextPage = "";
    if (form.getHasNextPage())
       nextPage = NEXTPAGE;

    pageContext.setAttribute(URLNAME, url.toString());
    pageContext.setAttribute(START, Integer.toString(start));
    pageContext.setAttribute(COUNT, Integer.toString(count));
    pageContext.setAttribute(ALLCOUNT, Integer.toString(allCount));
    pageContext.setAttribute(NEXTPAGE, nextPage);

    int currentPage = (start / count) + 1;
    //当前只有一页,没有下一页
    if ((currentPage == 1) && (!form.getHasNextPage())){
      pageContext.setAttribute(DISP, "off"); //不显示其它标识
    }else
      pageContext.setAttribute(DISP, "on");



    // Evaluate the body of this tag
    return (EVAL_BODY_INCLUDE);

  }

  /**
   * Render the end of the hyperlink.
   *
   * @exception JspException if a JSP exception has occurred
   */
  public int doEndTag() throws JspException {

    return (EVAL_PAGE);

  }

  /**
   * Release any acquired resources.
   */
  public void release() {

    super.release();


  }
  public String getActionFormName() {
    return actionFormName;
  }
  public void setActionFormName(String actionFormName) {
    this.actionFormName = actionFormName;
  }

}

⌨️ 快捷键说明

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