/** 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"); }
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); } } }
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"); }
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; }