Example #1
0
  /**
   * Function to build a datastructure filled with rows from a {@link TupleTable}, to be serialised
   * by Gson and displayed from there by a jqGrid.
   *
   * @param rowCount The number of rows to select.
   * @param totalPages The total number of pages of data (ie. dependent on size of dataset and nr.
   *     of rows per page)
   * @param page The selected page.
   * @param table The Tupletable from which to read the data.
   * @return
   */
  public static JQGridResult buildJQGridResults(
      final int rowCount, final int totalPages, final int page, final TupleTable table)
      throws TableException {
    final JQGridResult result = new JQGridResult(page, totalPages, rowCount);
    for (final Tuple row : table.getRows()) {
      System.out.println("check: " + row);
      final LinkedHashMap<String, String> rowMap = new LinkedHashMap<String, String>();

      final List<String> fieldNames = row.getFieldNames();
      for (final String fieldName : fieldNames) {
        final String rowValue = !row.isNull(fieldName) ? row.getString(fieldName) : "null";
        rowMap.put(fieldName, rowValue); // TODO encode to HTML
      }
      result.rows.add(rowMap);
    }
    return result;
  }