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();
}
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");
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations