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