Ejemplo n.º 1
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);
    }
  }