protected void encodeColumnFooter(FacesContext context, DataTable table, UIColumn column) throws IOException { if (!column.isRendered()) { return; } ResponseWriter writer = context.getResponseWriter(); String style = column.getStyle(); String styleClass = column.getStyleClass(); styleClass = styleClass == null ? DataTable.COLUMN_FOOTER_CLASS : DataTable.COLUMN_FOOTER_CLASS + " " + styleClass; writer.startElement("td", null); writer.writeAttribute("class", styleClass, null); if (style != null) writer.writeAttribute("style", style, null); if (column.getRowspan() != 1) writer.writeAttribute("rowspan", column.getRowspan(), null); if (column.getColspan() != 1) writer.writeAttribute("colspan", column.getColspan(), null); // Footer content UIComponent facet = column.getFacet("footer"); String text = column.getFooterText(); if (facet != null) { facet.encodeAll(context); } else if (text != null) { writer.write(text); } writer.endElement("td"); }
public void encodeColGroup(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("colgroup", null); for (UIColumn column : table.getColumns()) { if (column.isRendered()) { writer.startElement("col", null); writer.endElement("col"); } } writer.endElement("colgroup"); }
protected String getColumnTag(UIColumn column) { String headerText = column.getHeaderText(); UIComponent facet = column.getFacet("header"); if (headerText != null) { return headerText.toLowerCase(); } else if (facet != null) { return exportValue(FacesContext.getCurrentInstance(), facet).toLowerCase(); } else { throw new FacesException("No suitable xml tag found for " + column); } }
protected void encodeColumnSelection( FacesContext context, DataTable table, String clientId, UIColumn column, boolean selected) throws IOException { String selectionMode = column.getSelectionMode(); boolean disabled = column.isDisabledSelection(); if (selectionMode.equalsIgnoreCase("single")) { encodeRadio(context, table, selected, disabled); } else if (selectionMode.equalsIgnoreCase("multiple")) { encodeCheckbox(context, table, selected, disabled, HTML.CHECKBOX_CLASS); } else { throw new FacesException("Invalid column selection mode:" + selectionMode); } }
protected SelectItem[] getFilterOptions(UIColumn column) { Object options = column.getFilterOptions(); if (options instanceof SelectItem[]) { return (SelectItem[]) options; } else if (options instanceof Collection<?>) { return ((Collection<SelectItem>) column.getFilterOptions()).toArray(new SelectItem[] {}); } else { throw new FacesException( "Filter options for column " + column.getClientId() + " should be a SelectItem array or collection"); } }
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 encodeColumnHeaderContent(FacesContext context, UIColumn column, String sortIcon) throws IOException { ResponseWriter writer = context.getResponseWriter(); UIComponent header = column.getFacet("header"); String headerText = column.getHeaderText(); writer.startElement("span", null); if (header != null) header.encodeAll(context); else if (headerText != null) writer.write(headerText); writer.endElement("span"); if (sortIcon != null) { writer.startElement("span", null); writer.writeAttribute("class", sortIcon, null); writer.endElement("span"); } }
protected void encodeCell( FacesContext context, DataTable table, UIColumn column, String clientId, boolean selected) throws IOException { if (!column.isRendered()) { return; } ResponseWriter writer = context.getResponseWriter(); boolean selectionEnabled = column.getSelectionMode() != null; String style = column.getStyle(); String styleClass = selectionEnabled ? DataTable.SELECTION_COLUMN_CLASS : (column.getCellEditor() != null) ? DataTable.EDITABLE_COLUMN_CLASS : null; String userStyleClass = column.getStyleClass(); styleClass = userStyleClass == null ? styleClass : (styleClass == null) ? userStyleClass : styleClass + " " + userStyleClass; writer.startElement("td", null); writer.writeAttribute("role", "gridcell", null); if (style != null) writer.writeAttribute("style", style, null); if (styleClass != null) writer.writeAttribute("class", styleClass, null); if (selectionEnabled) encodeColumnSelection(context, table, clientId, column, selected); else column.encodeAll(context); writer.endElement("td"); }
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(); } }
protected void encodeFilter(FacesContext context, DataTable table, UIColumn column) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ResponseWriter writer = context.getResponseWriter(); String separator = String.valueOf(UINamingContainer.getSeparatorChar(context)); String filterId = column.getContainerClientId(context) + separator + "filter"; String filterStyleClass = column.getFilterStyleClass(); String filterValue = null; if (table.isReset()) { filterValue = ""; } else { if (params.containsKey(filterId)) { filterValue = params.get(filterId); } else { ValueExpression filterValueVE = column.getValueExpression("filterValue"); if (filterValueVE != null) { filterValue = (String) filterValueVE.getValue(context.getELContext()); } else { filterValue = ""; } } } if (column.getValueExpression("filterOptions") == null) { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_INPUT_FILTER_CLASS : DataTable.COLUMN_INPUT_FILTER_CLASS + " " + filterStyleClass; writer.startElement("input", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); writer.writeAttribute("value", filterValue, null); writer.writeAttribute("autocomplete", "off", null); if (column.getFilterStyle() != null) writer.writeAttribute("style", column.getFilterStyle(), null); if (column.getFilterMaxLength() != Integer.MAX_VALUE) writer.writeAttribute("maxlength", column.getFilterMaxLength(), null); writer.endElement("input"); } else { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_FILTER_CLASS : DataTable.COLUMN_FILTER_CLASS + " " + filterStyleClass; writer.startElement("select", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); SelectItem[] itemsArray = (SelectItem[]) getFilterOptions(column); for (SelectItem item : itemsArray) { Object itemValue = item.getValue(); writer.startElement("option", null); writer.writeAttribute("value", item.getValue(), null); if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) { writer.writeAttribute("selected", "selected", null); } writer.writeText(item.getLabel(), null); writer.endElement("option"); } writer.endElement("select"); } }
protected void encodeColumnHeader(FacesContext context, DataTable table, UIColumn column) throws IOException { if (!column.isRendered()) { return; } ResponseWriter writer = context.getResponseWriter(); String clientId = column.getContainerClientId(context); Object tableSortBy = table.getSortBy(); Object columnSortBy = column.getSortBy(); boolean isSortable = columnSortBy != null; boolean hasFilter = column.getFilterBy() != null; String selectionMode = column.getSelectionMode(); String sortIcon = null; boolean resizable = table.isResizableColumns() && column.isResizable(); String columnClass = isSortable ? DataTable.COLUMN_HEADER_CLASS + " " + DataTable.SORTABLE_COLUMN_CLASS : DataTable.COLUMN_HEADER_CLASS; columnClass = hasFilter ? columnClass + " " + DataTable.FILTER_COLUMN_CLASS : columnClass; columnClass = selectionMode != null ? columnClass + " " + DataTable.SELECTION_COLUMN_CLASS : columnClass; columnClass = resizable ? columnClass + " " + DataTable.RESIZABLE_COLUMN_CLASS : columnClass; columnClass = column.getStyleClass() != null ? columnClass + " " + column.getStyleClass() : columnClass; if (isSortable) { if (tableSortBy != null) { if (table.isMultiSort()) { List<SortMeta> sortMeta = table.getMultiSortMeta(); if (sortMeta != null) { for (SortMeta meta : sortMeta) { sortIcon = resolveDefaultSortIcon( columnSortBy, meta.getColumn().getSortBy(), meta.getSortOrder().name()); if (sortIcon != null) { break; } } } } else { sortIcon = resolveDefaultSortIcon(columnSortBy, tableSortBy, table.getSortOrder()); } } if (sortIcon == null) sortIcon = DataTable.SORTABLE_COLUMN_ICON_CLASS; else columnClass += " ui-state-active"; } String style = column.getStyle(); String width = column.getWidth(); if (width != null) { String unit = width.endsWith("%") ? "" : "px"; if (style != null) style = style + ";width:" + width + unit; else style = "width:" + width + unit; } writer.startElement("th", null); writer.writeAttribute("id", clientId, null); writer.writeAttribute("class", columnClass, null); writer.writeAttribute("role", "columnheader", null); if (style != null) writer.writeAttribute("style", style, null); if (column.getRowspan() != 1) writer.writeAttribute("rowspan", column.getRowspan(), null); if (column.getColspan() != 1) writer.writeAttribute("colspan", column.getColspan(), null); if (hasFilter) { table.enableFiltering(); String filterPosition = column.getFilterPosition(); if (filterPosition.equals("bottom")) { encodeColumnHeaderContent(context, column, sortIcon); encodeFilter(context, table, column); } else if (filterPosition.equals("top")) { encodeFilter(context, table, column); encodeColumnHeaderContent(context, column, sortIcon); } else { throw new FacesException( filterPosition + " is an invalid option for filterPosition, valid values are 'bottom' or 'top'."); } } else { encodeColumnHeaderContent(context, column, sortIcon); } if (selectionMode != null && selectionMode.equalsIgnoreCase("multiple")) { encodeCheckbox(context, table, false, column.isDisabledSelection(), HTML.CHECKBOX_ALL_CLASS); } writer.endElement("th"); }