@SuppressWarnings("unchecked")
  @Override
  public void setDataAndLimitVariables(TableFacade tableFacade) {
    // initialize i18n
    resword = ResourceBundleProvider.getWordsBundle(getLocale());
    resformat = ResourceBundleProvider.getFormatBundle(getLocale());

    Limit limit = tableFacade.getLimit();
    ListSubjectFilter listSubjectFilter = getListSubjectFilter(limit);

    if (!limit.isComplete()) {
      int totalRows = getSubjectDao().getCountWithFilter(listSubjectFilter, getCurrentStudy());
      tableFacade.setTotalRows(totalRows);
    }

    ListSubjectSort listSubjectSort = getListSubjectSort(limit);
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();

    Collection<SubjectBean> items =
        getSubjectDao()
            .getWithFilterAndSort(
                getCurrentStudy(), listSubjectFilter, listSubjectSort, rowStart, rowEnd);
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();

    for (SubjectBean subject : items) {
      UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(subject.getOwnerId());
      UserAccountBean updater =
          subject.getUpdaterId() == 0
              ? null
              : (UserAccountBean) getUserAccountDao().findByPK(subject.getUpdaterId());
      HashMap<Object, Object> h = new HashMap<Object, Object>();
      String studySubjectIdAndStudy = "";
      List<StudySubjectBean> studySubjects =
          getStudySubjectDao().findAllBySubjectId(subject.getId());
      for (StudySubjectBean studySubjectBean : studySubjects) {
        StudyBean study = (StudyBean) getStudyDao().findByPK(studySubjectBean.getStudyId());
        studySubjectIdAndStudy += studySubjectIdAndStudy.length() == 0 ? "" : ",";
        studySubjectIdAndStudy += study.getIdentifier() + "-" + studySubjectBean.getLabel();
      }

      h.put("studySubjectIdAndStudy", studySubjectIdAndStudy);
      h.put("subject", subject);
      h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
      h.put("subject.gender", subject.getGender());
      h.put("subject.createdDate", subject.getCreatedDate());
      h.put("subject.owner", owner);
      h.put("subject.updatedDate", subject.getUpdatedDate());
      h.put("subject.updater", updater);
      h.put("subject.status", subject.getStatus());

      theItems.add(h);
    }

    tableFacade.setItems(theItems);
  }
Example #2
0
  @Override
  public String render() {

    Limit limit = getCoreContext().getLimit();
    int page = limit.getRowSelect().getPage();

    StringBuilder action = new StringBuilder("javascript:");
    action.append(
        "jQuery.jmesa.setPage('"
            + limit.getId()
            + "','"
            + (page + 1)
            + "');"
            + getOnInvokeActionJavaScript());

    int totalPages = HtmlUtils.totalPages(getCoreContext());
    if (!HtmlUtils.isNextPageEnabled(page, totalPages)) {
      return disabled();
    }

    return enabled(action.toString());
  }
  @Override
  public String execute() throws Exception {

    String tblid = "etairportTbl";
    TableFacade tableFacade = new TableFacadeImpl(tblid, request);

    tableFacade.setStateAttr("restore");
    tableFacade.setEditable(false);

    tableFacade.setMaxRows(10);
    // tableFacade.setTotalRows(etairports.size());
    tableFacade.setMaxRowsIncrements(10, 20, 50);
    Limit limit = tableFacade.getLimit();

    RowSelect rowSelect = limit.getRowSelect();

    FilterSet filterSet = limit.getFilterSet();
    Collection<Filter> filters = filterSet.getFilters();

    // tableFacade.setItems(etairports);

    request.setAttribute("traveler_tbl", ""); // buildTable(tableFacade)
    return SUCCESS;
  }
  @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";
  }