/**
   * A very custom way to sort the items. The AuditUserLoginSort acts as a command for the Hibernate
   * criteria object. Take the Limit information and sort the rows.
   *
   * @param limit The Limit to use.
   */
  protected ListSubjectSort getListSubjectSort(Limit limit) {
    ListSubjectSort listSubjectSort = new ListSubjectSort();
    SortSet sortSet = limit.getSortSet();
    Collection<Sort> sorts = sortSet.getSorts();
    for (Sort sort : sorts) {
      String property = sort.getProperty();
      String order = sort.getOrder().toParam();
      listSubjectSort.addSort(property, order);
    }

    return listSubjectSort;
  }
  @SuppressWarnings("unchecked")
  public String paging() {
    String tblid = "traveler_tbl";

    TableFacade tableFacade = new TableFacadeImpl(tblid, request);
    String min = request.getParameter(tblid + "_rng_min");
    String max = request.getParameter(tblid + "_rng_max");
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date mindate = null;
    Date maxdate = null;
    if (min != null && max != null) {
      try {
        mindate = dateFormat.parse(min);
        maxdate = dateFormat.parse(max);
        System.out.println("mindate=" + mindate + ";maxdate=" + maxdate);
        HttpSession session = request.getSession();
        if (session != null) {
          session.setAttribute(tblid + "_rng_min", mindate);
          session.setAttribute(tblid + "_rng_max", maxdate);
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }

    } else {
      HttpSession session = request.getSession();
      if (session != null) {
        mindate = (Date) session.getAttribute(tblid + "_rng_min");
        maxdate = (Date) session.getAttribute(tblid + "_rng_max");
      }
    }
    tableFacade.setStateAttr("restore");
    tableFacade.setMaxRows(10);
    Map<String, Object> param = new HashMap(2);
    PagingAndSorting pg = new PagingAndSorting();

    String sql = "select o from " + TargetCustomerTicket.class.getName() + " as o ";
    if (mindate != null && maxdate != null) {
      sql += " where o.fltDate>=:mindate and o.fltDate<=:maxdate";
      param.put("mindate", mindate);
      param.put("maxdate", maxdate);
    }
    etairports = this.baseService.query(sql, param, null);
    tableFacade.setTotalRows(etairports.size());
    tableFacade.setMaxRowsIncrements(10, 20, 50);
    Limit limit = tableFacade.getLimit();
    RowSelect rowSelect = limit.getRowSelect();
    SortSet sortSet = limit.getSortSet();
    if (sortSet != null) {
      Collection<Sort> sorts = sortSet.getSorts();
      if (sorts != null) {
        for (Iterator iterator = sorts.iterator(); iterator.hasNext(); ) {
          Sort sort = (Sort) iterator.next();
          Order order = sort.getOrder();
          String s = "";
          if (order.equals(Order.ASC)) s = "asc";
          if (order.equals(Order.DESC)) s = "desc";
          int position = sort.getPosition();
          String property = sort.getProperty();
          System.out.println(
              "{property:'" + property + "',position:" + position + ",order:'" + s + "'}");
        }
      }
    }
    if (rowSelect != null) {
      int rowStart = rowSelect.getRowStart();
      int rowEnd = rowSelect.getRowEnd();
      int page = rowSelect.getPage();
      System.out.println("rowstart=" + rowStart + ";rowend=" + rowEnd + ";page=" + page);
      ArrayList rs = new ArrayList(10);
      for (int i = rowStart; i < rowEnd && i < etairports.size(); i++) {
        rs.add(etairports.get(i));
      }
      tableFacade.setItems(rs);
    }
    final String buildTable = buildTable(tableFacade);
    ByteArrayInputStream inputStream = null;
    try {
      inputStream = new ByteArrayInputStream(buildTable.getBytes("UTF8"));
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    this.setPgInputStream(inputStream);
    return "pgresult";
  }