예제 #1
0
  /** Render column headers either in single row or nested if a columnGroup is defined */
  protected void encodeThead(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    ColumnGroup group = table.getColumnGroup("header");

    writer.startElement("thead", null);
    writer.writeAttribute("id", table.getClientId(context) + "_head", null);

    if (group != null && group.isRendered()) {

      for (UIComponent child : group.getChildren()) {
        if (child.isRendered() && child instanceof Row) {
          Row headerRow = (Row) child;

          writer.startElement("tr", null);

          for (UIComponent headerRowChild : headerRow.getChildren()) {
            if (headerRowChild.isRendered() && headerRowChild instanceof Column) {
              encodeColumnHeader(context, table, (Column) headerRowChild);
            }
          }

          writer.endElement("tr");
        }
      }

    } else {
      writer.startElement("tr", null);
      writer.writeAttribute("role", "row", null);

      for (UIColumn column : table.getColumns()) {
        if (column instanceof Column) {
          encodeColumnHeader(context, table, column);
        } else if (column instanceof DynamicColumn) {
          DynamicColumn dynamicColumn = (DynamicColumn) column;
          dynamicColumn.applyModel();

          encodeColumnHeader(context, table, dynamicColumn);
        }
      }

      writer.endElement("tr");
    }

    encodeFrozenRows(context, table);

    writer.endElement("thead");
  }
예제 #2
0
  protected void encodeTFoot(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    ColumnGroup group = table.getColumnGroup("footer");

    writer.startElement("tfoot", null);

    if (group != null && group.isRendered()) {

      for (UIComponent child : group.getChildren()) {
        if (child.isRendered() && child instanceof Row) {
          Row footerRow = (Row) child;

          writer.startElement("tr", null);

          for (UIComponent footerRowChild : footerRow.getChildren()) {
            if (footerRowChild.isRendered() && footerRowChild instanceof Column) {
              encodeColumnFooter(context, table, (Column) footerRowChild);
            }
          }

          writer.endElement("tr");
        }
      }

    } else if (table.hasFooterColumn()) {
      writer.startElement("tr", null);

      for (UIColumn column : table.getColumns()) {
        if (column instanceof Column) {
          encodeColumnFooter(context, table, column);
        } else if (column instanceof DynamicColumn) {
          DynamicColumn dynamicColumn = (DynamicColumn) column;
          dynamicColumn.applyModel();

          encodeColumnFooter(context, table, dynamicColumn);
        }
      }

      writer.endElement("tr");
    }

    writer.endElement("tfoot");
  }
예제 #3
0
  public void encode(FacesContext context, DataTableRenderer renderer, DataTable table)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String clientId = table.getClientId(context);
    String[] cellInfo = params.get(clientId + "_cellInfo").split(",");
    int rowIndex = Integer.parseInt(cellInfo[0]);
    int cellIndex = Integer.parseInt(cellInfo[1]);
    int i = -1;
    UIColumn column = null;
    for (UIColumn col : table.getColumns()) {
      if (col.isRendered()) {
        i++;

        if (i == cellIndex) {
          column = col;
          break;
        }
      }
    }

    table.setRowIndex(rowIndex);

    if (column.isDynamic()) {
      DynamicColumn dynamicColumn = (DynamicColumn) column;
      dynamicColumn.applyStatelessModel();
    }

    if (table.isCellEditEscapeRequest(context)) {
      column.getCellEditor().getFacet("input").encodeAll(context);
    } else {
      column.getCellEditor().getFacet("output").encodeAll(context);
    }

    if (column.isDynamic()) {
      ((DynamicColumn) column).cleanStatelessModel();
    }
  }
예제 #4
0
  protected void exportCells(DataTable table, Writer writer) throws IOException {
    for (UIColumn col : table.getColumns()) {
      if (!col.isRendered()) {
        continue;
      }

      if (col instanceof DynamicColumn) {
        ((DynamicColumn) col).applyModel();
      }

      if (col.isExportable()) {
        String columnTag = getColumnTag(col);

        addColumnValue(writer, col.getChildren(), columnTag);
      }
    }
  }
예제 #5
0
  public boolean encodeRow(
      FacesContext context, DataTable table, String clientId, int rowIndex, String rowIndexVar)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    boolean selectionEnabled = table.isSelectionEnabled();

    Object rowKey = null;
    if (selectionEnabled) {
      // try rowKey attribute
      rowKey = table.getRowKey();

      // ask selectable datamodel
      if (rowKey == null) rowKey = table.getRowKeyFromModel(table.getRowData());
    }

    // Preselection
    boolean selected = table.getSelectedRowKeys().contains(rowKey);

    String userRowStyleClass = table.getRowStyleClass();
    String rowStyleClass =
        rowIndex % 2 == 0
            ? DataTable.ROW_CLASS + " " + DataTable.EVEN_ROW_CLASS
            : DataTable.ROW_CLASS + " " + DataTable.ODD_ROW_CLASS;

    if (selected) {
      rowStyleClass = rowStyleClass + " ui-state-highlight";
    }

    if (userRowStyleClass != null) {
      rowStyleClass = rowStyleClass + " " + userRowStyleClass;
    }

    if (table.isEditingRow()) {
      rowStyleClass = rowStyleClass + " " + DataTable.EDITING_ROW_CLASS;
    }

    writer.startElement("tr", null);
    writer.writeAttribute("data-ri", rowIndex, null);
    if (rowKey != null) {
      writer.writeAttribute("data-rk", rowKey, null);
    }
    writer.writeAttribute("class", rowStyleClass, null);
    writer.writeAttribute("role", "row", null);
    if (selectionEnabled) {
      writer.writeAttribute("aria-selected", String.valueOf(selected), null);
    }

    for (UIColumn column : table.getColumns()) {
      if (column instanceof Column) {
        encodeCell(context, table, column, clientId, selected);
      } else if (column instanceof DynamicColumn) {
        DynamicColumn dynamicColumn = (DynamicColumn) column;
        dynamicColumn.applyModel();

        encodeCell(context, table, dynamicColumn, null, false);
      }
    }

    writer.endElement("tr");

    return true;
  }