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

📄 mpagetag.java

📁 用jbuilder写的源程序
💻 JAVA
字号:
/**
 * Copyright 2003-2006 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("[JdonFramework]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 ((allCount > (start + count)) )
       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 = 1;
    if (count > 0 ){
        currentPage = (start / count) + 1;    
    }
    
    //当前只有一页,没有下一页
    if ((currentPage == 1) && (nextPage.length() == 0)){
      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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -