コード例 #1
0
  /**
   * Get data size
   *
   * @param pageContext
   * @param dataRecords
   * @param filterData
   * @return
   * @throws Exception
   */
  public static Integer getSmartDataSize(
      PageContext pageContext, Map<String, String> parameters, IDataRecordList<?> dataRecords)
      throws Exception {
    Integer dataSize = 0;

    // get dataRecords
    IDataRecordList<?> records = dataRecords;
    if (records == null) {
      // get them from the request
      Object obj = pageContext.getRequest().getAttribute(SmartConstants.DATA);
      if (obj != null && obj instanceof IDataRecordList<?>) records = (IDataRecordList<?>) obj;
    }

    // get filter data
    // get it from the request
    String filterName = parameters.get(SmartConstants.PARAM_NAME);
    FilterData fd = FilterDataUtil.getFilterData(pageContext, filterName);
    if (fd != null) {
      // if the object implement the IEnableFilter interface. then get the data from the
      // "getFilterRecords" method.
      if (records instanceof IEnableFilter<?>) {
        // change to IEnableFilter object
        IEnableFilter<?> filterList = (IEnableFilter<?>) records;
        dataSize = filterList.getFilterRecordSize(fd);
      }
    } else {
      dataSize = records.getAllRecordSize();
    }
    return dataSize;
  }
コード例 #2
0
  /**
   * PRIORITY:context JSP file > interface if user has define the data by user the "list" attribute,
   * then get it at first TODO get the row data from the context
   *
   * @return
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public static List<SmartRow> getSmartRowList(
      SmartTableContext context, IDataRecordList<?> dataRecords) throws Exception {
    PageContext pageContext = context.getPageContext();
    List<SmartRow> srs = new ArrayList<SmartRow>();

    Map<String, String> parameters = context.getParameters();
    PreferenceConfigure configure = context.getConfigure();

    // get dataRecords
    IDataRecordList<?> records = dataRecords;
    if (records == null) {
      // get them from the request
      Object obj = pageContext.getRequest().getAttribute(SmartConstants.DATA);
      if (obj != null && obj instanceof IDataRecordList) records = (IDataRecordList<?>) obj;
    }

    // get filter data
    // get it from the request
    String filterName = parameters.get(SmartConstants.PARAM_NAME);
    FilterData fd = FilterDataUtil.getFilterData(pageContext, filterName);

    // if can not find the sort by and sort order in the parameters.
    // get the default value from the configure object.
    String sortBy = parameters.get(SmartConstants.PARAMS_SORT_BY);
    if (sortBy == null) sortBy = configure.getSortBy();

    String order = parameters.get(SmartConstants.PARAMS_SORT_ORDER);
    if (order == null) order = configure.getSortOrder();
    SortOrder sortOrder = SortOrderUtil.transfer(order);

    // transfer IDataRecordList to SmartRow object
    // get the row data from the context
    List beans = new ArrayList();
    if (fd != null) {
      // if the object implement the IEnableFilter interface. then get the data from the
      // "getFilterRecords" method.
      if (records instanceof IEnableFilter) {
        // change to IEnableFilter object
        IEnableFilter<?> filterList = (IEnableFilter<?>) records;

        Integer dataSize = filterList.getFilterRecordSize(fd);
        Integer beginIndex = getBeginIndex(dataSize, context);
        Integer endIndex = getEndIndex(dataSize, context);

        // invoke the getFilterRecords method
        beans = filterList.getFilterRecords(fd, beginIndex, endIndex, sortBy, sortOrder);
      }
    } else {
      Integer dataSize = records.getAllRecordSize();
      Integer beginIndex = getBeginIndex(dataSize, context);
      Integer endIndex = getEndIndex(dataSize, context);

      // invoke the getRecords method
      beans = records.getRecords(beginIndex, endIndex, sortBy, sortOrder);
    }

    // get the current page smart row object
    for (int i = 0; i < beans.size(); i++) {
      Object bean = beans.get(i);
      SmartRow row = new SmartRow();

      row.setObj(bean);
      srs.add(row);
    }
    return srs;
  }