Package edu.zzuli.model.core

Source Code of edu.zzuli.model.core.JqGridBaseAction

package edu.zzuli.model.core;

import java.util.Collections;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

import edu.zzuli.common.Pagination;

/**
* @author tianshaojie
* @date 2011-7-16
* @discription : jqGrid分页封装类
* 根据jsonReader中的设置,解析json数据。
* 根据jsonReader中的root(我设置的是“gridModel”),得到数据记录数组;
* 根据rows得到每页显示的行数;根据page设置当前页数;
* 根据records(我设置的是“record”)得到所有记录数量;
* 根据total得到所有页数。
*/
@SuppressWarnings("serial")
public abstract class JqGridBaseAction<T> extends ActionSupport {
 
  private Integer rows = 0;    //每页行数(从前台自动获取)pageSize
 
  private Integer page = 0;    //当前页号(从前台自动获取)currentPage
 
  private Integer total = 0;    //总页数  totalPages
 
  private Integer record = 0;    //总数据条数  totalRows
 
  private String sord;      //排序的方式
 
  private String sidx;      //用于排序的列名
 
  private String search;      //用于查询的请
 
  private List<T> gridModel;    //用于得到返回客户端的实际json数据

  /**
   * @author tianshaojie
   * @date 2011-7-16
   * @discription : 抽象方法,继承子类实现,获得记录总条数(old)
   * @return int
   */
  //public abstract int getResultSize();

  /**
   * @author tianshaojie
   * @date 2011-7-16
   * @discription : 获得当分页数据(old)
   * @param from  :开始位置    rows * (page - 1)
   * @param length:每页数据条数  length = rows
   * @return List<T>
   */
  //public abstract List<T> listResults(int from, int length);

  /**
   * @author tianshaojie
   * @date 2011-7-16
   * @discription : 通过Pagination获得结果集(这样查询总条数和结果集放在一个操作里面即可获得,减少数据库访问连接)
   * @param pagination
   * @return List<T>
   */
  public abstract List<T> listResults(Pagination pagination);
 
  /**
   * @author tianshaojie
   * @date 2011-3-27
   * @discription : 为gridModel、record、total赋值,这些值也将会传回客户端。
   * @return String
   */
  public String refreshGridModel() {
    try {
      List<T> results = Collections.emptyList();
     
      /*record = this.getResultSize();
      int from = rows * (page - 1);
      int length = rows;
      results = this.listResults(from, length);
      this.setGridModel(results);*/
     
      if (rows > 0 && page > 0) {
        Pagination pagination = new Pagination(rows, page);
        results = this.listResults(pagination);
        record = pagination.getTotalRows()//总记录条数
        this.setGridModel(results);
      }
//      if (results != null && results.size() > 0) {
//        this.setGridModel(results);
//      }
     
      total = (int) Math.ceil((double) record / (double) rows);//总页数
      return SUCCESS;
    } catch (Exception e) {
      e.printStackTrace();
      this.addActionError(e.getMessage());
      return ERROR;
    }
  }

  public List<T> getGridModel() {
    return gridModel;
  }

  public void setGridModel(List<T> gridModel) {
    this.gridModel = gridModel;
  }

  public Integer getRows() {
    return rows;
  }

  public void setRows(Integer rows) {
    this.rows = rows;
  }

  public Integer getPage() {
    return page;
  }

  public void setPage(Integer page) {
    this.page = page;
  }

  public Integer getTotal() {
    return total;
  }

  public void setTotal(Integer total) {
    this.total = total;
  }

  public Integer getRecord() {
    return record;
  }

  public void setRecord(Integer record) {
    this.record = record;
  }

  public String getSord() {
    return sord;
  }

  public void setSord(String sord) {
    this.sord = sord;
  }

  public String getSidx() {
    return sidx;
  }

  public void setSidx(String sidx) {
    this.sidx = sidx;
  }

  public String getSearch() {
    return search;
  }

  public void setSearch(String search) {
    this.search = search;
  }
}
TOP

Related Classes of edu.zzuli.model.core.JqGridBaseAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.