Search in sources :

Example 1 with DynamicColumn

use of org.primefaces.component.api.DynamicColumn in project primefaces by primefaces.

the class RowExpressionResolver method resolveClientIds.

@Override
public String resolveClientIds(FacesContext context, UIComponent source, UIComponent last, String expression, Set<SearchExpressionHint> hints) {
    int row = validate(context, source, last, expression);
    UIData data = (UIData) last;
    char separatorChar = UINamingContainer.getSeparatorChar(context);
    StringBuilder clientIds = new StringBuilder();
    for (UIComponent column : data.getChildren()) {
        // handle dynamic columns
        if (column instanceof Columns) {
            List<DynamicColumn> dynamicColumns = ((Columns) column).getDynamicColumns();
            for (int i = 0; i < dynamicColumns.size(); i++) {
                DynamicColumn dynamicColumn = dynamicColumns.get(i);
                for (UIComponent comp : column.getChildren()) {
                    if (clientIds.length() > 0) {
                        clientIds.append(" ");
                    }
                    clientIds.append(data.getClientId(context));
                    clientIds.append(separatorChar);
                    clientIds.append(row);
                    clientIds.append(separatorChar);
                    clientIds.append(dynamicColumn.getId());
                    clientIds.append(separatorChar);
                    clientIds.append(i);
                    clientIds.append(separatorChar);
                    clientIds.append(comp.getId());
                }
            }
        } else if (column instanceof UIColumn) {
            for (UIComponent cell : column.getChildren()) {
                if (clientIds.length() > 0) {
                    clientIds.append(" ");
                }
                clientIds.append(data.getClientId(context));
                clientIds.append(separatorChar);
                clientIds.append(row);
                clientIds.append(separatorChar);
                clientIds.append(cell.getId());
            }
        }
    }
    return clientIds.toString();
}
Also used : UIColumn(javax.faces.component.UIColumn) UIComponent(javax.faces.component.UIComponent) Columns(org.primefaces.component.columns.Columns) DynamicColumn(org.primefaces.component.api.DynamicColumn) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint) UIData(javax.faces.component.UIData)

Example 2 with DynamicColumn

use of org.primefaces.component.api.DynamicColumn in project primefaces by primefaces.

the class DataTableRenderer method encodeThead.

protected void encodeThead(FacesContext context, DataTable table, int columnStart, int columnEnd, String theadId, String columnGroupType) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    List<UIColumn> columns = table.getColumns();
    String theadClientId = (theadId == null) ? table.getClientId(context) + "_head" : theadId;
    String colGroupType = (columnGroupType == null) ? "header" : columnGroupType;
    ColumnGroup group = table.getColumnGroup(colGroupType);
    writer.startElement("thead", null);
    writer.writeAttribute("id", theadClientId, null);
    if (group != null && group.isRendered()) {
        context.getAttributes().put(Constants.HELPER_RENDERER, "columnGroup");
        for (UIComponent child : group.getChildren()) {
            if (child.isRendered()) {
                if (child instanceof Row) {
                    Row headerRow = (Row) child;
                    String rowClass = headerRow.getStyleClass();
                    String rowStyle = headerRow.getStyle();
                    writer.startElement("tr", null);
                    writer.writeAttribute("role", "row", null);
                    if (rowClass != null) {
                        writer.writeAttribute("class", rowClass, null);
                    }
                    if (rowStyle != null) {
                        writer.writeAttribute("style", rowStyle, null);
                    }
                    for (UIComponent headerRowChild : headerRow.getChildren()) {
                        if (headerRowChild.isRendered()) {
                            if (headerRowChild instanceof Column) {
                                encodeColumnHeader(context, table, (Column) headerRowChild);
                            } else if (headerRowChild instanceof Columns) {
                                List<DynamicColumn> dynamicColumns = ((Columns) headerRowChild).getDynamicColumns();
                                for (DynamicColumn dynaColumn : dynamicColumns) {
                                    dynaColumn.applyModel();
                                    encodeColumnHeader(context, table, dynaColumn);
                                }
                            } else {
                                headerRowChild.encodeAll(context);
                            }
                        }
                    }
                    writer.endElement("tr");
                } else {
                    child.encodeAll(context);
                }
            }
        }
        context.getAttributes().remove(Constants.HELPER_RENDERER);
    } else {
        writer.startElement("tr", null);
        writer.writeAttribute("role", "row", null);
        for (int i = columnStart; i < columnEnd; i++) {
            UIColumn column = columns.get(i);
            if (column instanceof DynamicColumn) {
                ((DynamicColumn) column).applyModel();
            }
            encodeColumnHeader(context, table, column);
        }
        writer.endElement("tr");
    }
    writer.endElement("thead");
}
Also used : UIColumn(org.primefaces.component.api.UIColumn) ResponseWriter(javax.faces.context.ResponseWriter) DynamicColumn(org.primefaces.component.api.DynamicColumn) Column(org.primefaces.component.column.Column) UIColumn(org.primefaces.component.api.UIColumn) UIComponent(javax.faces.component.UIComponent) Columns(org.primefaces.component.columns.Columns) SummaryRow(org.primefaces.component.summaryrow.SummaryRow) HeaderRow(org.primefaces.component.headerrow.HeaderRow) Row(org.primefaces.component.row.Row) ColumnGroup(org.primefaces.component.columngroup.ColumnGroup) DynamicColumn(org.primefaces.component.api.DynamicColumn)

Example 3 with DynamicColumn

use of org.primefaces.component.api.DynamicColumn in project primefaces by primefaces.

the class DataTableExcelExporter method addColumnFacets.

protected void addColumnFacets(DataTable table, Sheet sheet, DataTableExporter.ColumnType columnType) {
    int sheetRowIndex = sheet.getLastRowNum() + 1;
    Row rowHeader = sheet.createRow(sheetRowIndex);
    for (UIColumn col : getExportableColumns(table)) {
        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }
        UIComponent facet = col.getFacet(columnType.facet());
        String textValue;
        switch(columnType) {
            case HEADER:
                textValue = (col.getExportHeaderValue() != null) ? col.getExportHeaderValue() : col.getHeaderText();
                break;
            case FOOTER:
                textValue = (col.getExportFooterValue() != null) ? col.getExportFooterValue() : col.getFooterText();
                break;
            default:
                textValue = null;
                break;
        }
        if (textValue != null) {
            addColumnValue(rowHeader, textValue);
        } else if (ComponentUtils.shouldRenderFacet(facet)) {
            addColumnValue(rowHeader, facet);
        } else {
            addColumnValue(rowHeader, Constants.EMPTY_STRING);
        }
    }
}
Also used : UIColumn(org.primefaces.component.api.UIColumn) UIComponent(javax.faces.component.UIComponent) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) DynamicColumn(org.primefaces.component.api.DynamicColumn)

Example 4 with DynamicColumn

use of org.primefaces.component.api.DynamicColumn in project primefaces by primefaces.

the class DataTableExcelExporter method exportCells.

@Override
protected void exportCells(DataTable table, Object document) {
    Sheet sheet = (Sheet) document;
    int sheetRowIndex = sheet.getLastRowNum() + 1;
    Row row = sheet.createRow(sheetRowIndex);
    for (UIColumn col : getExportableColumns(table)) {
        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }
        addColumnValue(table, row, col.getChildren(), col);
    }
}
Also used : UIColumn(org.primefaces.component.api.UIColumn) DynamicColumn(org.primefaces.component.api.DynamicColumn)

Example 5 with DynamicColumn

use of org.primefaces.component.api.DynamicColumn in project primefaces by primefaces.

the class DataTablePDFExporter method addColumnFacets.

protected void addColumnFacets(DataTable table, PdfPTable pdfTable, ColumnType columnType) {
    for (UIColumn col : getExportableColumns(table)) {
        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyStatelessModel();
        }
        UIComponent facet = col.getFacet(columnType.facet());
        String textValue;
        switch(columnType) {
            case HEADER:
                textValue = (col.getExportHeaderValue() != null) ? col.getExportHeaderValue() : col.getHeaderText();
                break;
            case FOOTER:
                textValue = (col.getExportFooterValue() != null) ? col.getExportFooterValue() : col.getFooterText();
                break;
            default:
                textValue = null;
                break;
        }
        if (textValue != null) {
            addColumnValue(pdfTable, textValue, 1, 1);
        } else if (ComponentUtils.shouldRenderFacet(facet)) {
            addColumnValue(pdfTable, facet);
        } else {
            addColumnValue(pdfTable, Constants.EMPTY_STRING, 1, 1);
        }
    }
}
Also used : UIColumn(org.primefaces.component.api.UIColumn) UIComponent(javax.faces.component.UIComponent) DynamicColumn(org.primefaces.component.api.DynamicColumn)

Aggregations

DynamicColumn (org.primefaces.component.api.DynamicColumn)28 UIColumn (org.primefaces.component.api.UIColumn)21 UIComponent (javax.faces.component.UIComponent)14 ResponseWriter (javax.faces.context.ResponseWriter)7 Columns (org.primefaces.component.columns.Columns)7 Column (org.primefaces.component.column.Column)6 FacesException (javax.faces.FacesException)5 ColumnGroup (org.primefaces.component.columngroup.ColumnGroup)4 Row (org.primefaces.component.row.Row)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 ValueExpression (javax.el.ValueExpression)3 FacesContext (javax.faces.context.FacesContext)3 HeaderRow (org.primefaces.component.headerrow.HeaderRow)3 List (java.util.List)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 CellEditor (org.primefaces.component.celleditor.CellEditor)2 SummaryRow (org.primefaces.component.summaryrow.SummaryRow)2 ColumnMeta (org.primefaces.model.ColumnMeta)2 SimpleContext (de.odysseus.el.util.SimpleContext)1