Пример #1
0
  protected void encodeFrozenRows(FacesContext context, DataTable table) throws IOException {
    Collection<?> frozenRows = table.getFrozenRows();
    if (frozenRows == null || frozenRows.isEmpty()) {
      return;
    }

    ResponseWriter writer = context.getResponseWriter();
    String clientId = table.getClientId(context);
    String var = table.getVar();
    String rowIndexVar = table.getRowIndexVar();
    Map<String, Object> requestMap = context.getExternalContext().getRequestMap();

    writer.startElement("tbody", null);
    writer.writeAttribute("class", DataTable.DATA_CLASS, null);

    int index = 0;
    for (Iterator<? extends Object> it = frozenRows.iterator(); it.hasNext(); ) {
      requestMap.put(var, it.next());

      if (rowIndexVar != null) {
        requestMap.put(rowIndexVar, index);
      }

      encodeRow(context, table, clientId, index, rowIndexVar);
    }

    writer.endElement("tbody");
  }
Пример #2
0
  protected void encodeRowExpansion(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    int expandedRowIndex =
        Integer.parseInt(params.get(table.getClientId(context) + "_expandedRowIndex"));
    String rowIndexVar = table.getRowIndexVar();

    table.setRowIndex(expandedRowIndex);

    if (rowIndexVar != null) {
      context.getExternalContext().getRequestMap().put(rowIndexVar, expandedRowIndex);
    }

    writer.startElement("tr", null);
    writer.writeAttribute("style", "display:none", null);
    writer.writeAttribute(
        "class", DataTable.EXPANDED_ROW_CONTENT_CLASS + " ui-widget-content", null);

    writer.startElement("td", null);
    writer.writeAttribute("colspan", table.getColumnsCount(), null);

    table.getRowExpansion().encodeAll(context);

    writer.endElement("td");

    writer.endElement("tr");

    table.setRowIndex(-1);
  }
Пример #3
0
  public void encodeTbody(FacesContext context, DataTable table, boolean dataOnly)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String rowIndexVar = table.getRowIndexVar();
    String clientId = table.getClientId(context);
    String emptyMessage = table.getEmptyMessage();
    UIComponent emptyFacet = table.getFacet("emptyMessage");
    SubTable subTable = table.getSubTable();
    SummaryRow summaryRow = table.getSummaryRow();

    if (table.isSelectionEnabled()) {
      table.findSelectedRowKeys();
    }

    int rows = table.getRows();
    int first = table.getFirst();
    int rowCount = table.getRowCount();
    int rowCountToRender =
        rows == 0 ? (table.isLiveScroll() ? table.getScrollRows() : rowCount) : rows;
    boolean hasData = rowCount > 0;

    if (!dataOnly) {
      writer.startElement("tbody", null);
      writer.writeAttribute("id", clientId + "_data", null);
      writer.writeAttribute("class", DataTable.DATA_CLASS, null);
    }

    if (hasData) {
      for (int i = first; i < (first + rowCountToRender); i++) {
        if (subTable != null) {
          encodeSubTable(context, table, subTable, i, rowIndexVar);
        } else {

          table.setRowIndex(i);
          if (!table.isRowAvailable()) {
            break;
          }

          encodeRow(context, table, clientId, i, rowIndexVar);

          if (summaryRow != null && !isInSameGroup(context, table, i)) {
            table.setRowIndex(i); // restore
            encodeSummaryRow(context, table, summaryRow);
          }
        }
      }
    } else {
      // Empty message
      writer.startElement("tr", null);
      writer.writeAttribute("class", DataTable.EMPTY_MESSAGE_ROW_CLASS, null);

      writer.startElement("td", null);
      writer.writeAttribute("colspan", table.getColumnsCount(), null);

      if (emptyFacet != null) emptyFacet.encodeAll(context);
      else writer.write(emptyMessage);

      writer.endElement("td");

      writer.endElement("tr");
    }

    if (!dataOnly) {
      writer.endElement("tbody");
    }

    // Cleanup
    table.setRowIndex(-1);
    if (rowIndexVar != null) {
      context.getExternalContext().getRequestMap().remove(rowIndexVar);
    }
  }