Search in sources :

Example 1 with UIColumn

use of javax.faces.component.UIColumn 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 UIColumn

use of javax.faces.component.UIColumn in project primefaces by primefaces.

the class UITree method visitColumns.

private boolean visitColumns(VisitContext context, Lazy<TreeNode> root, VisitCallback callback, String rowKey, boolean visitNodes) {
    String treeNodeType = null;
    if (visitNodes) {
        setRowKey(root, rowKey);
        if (rowKey == null) {
            return false;
        }
        TreeNode rowNode = getRowNode();
        if (rowNode != null) {
            treeNodeType = rowNode.getType();
        }
    }
    if (getChildCount() > 0) {
        for (UIComponent child : getChildren()) {
            if (child instanceof Columns) {
                Columns columns = (Columns) child;
                for (int i = 0; i < columns.getRowCount(); i++) {
                    columns.setRowIndex(i);
                    boolean value = visitColumnContent(context, callback, columns);
                    if (value) {
                        columns.setRowIndex(-1);
                        return true;
                    }
                }
                columns.setRowIndex(-1);
            } else if (child instanceof UIColumn) {
                if (child instanceof UITreeNode) {
                    UITreeNode uiTreeNode = (UITreeNode) child;
                    if (visitNodes && treeNodeType != null && !treeNodeType.equals(uiTreeNode.getType())) {
                        continue;
                    }
                }
                if (child.visitTree(context, callback)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : UIColumn(javax.faces.component.UIColumn) UITreeNode(org.primefaces.component.tree.UITreeNode) TreeNode(org.primefaces.model.TreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) Columns(org.primefaces.component.columns.Columns) UITreeNode(org.primefaces.component.tree.UITreeNode)

Example 3 with UIColumn

use of javax.faces.component.UIColumn in project liferay-faces-alloy by liferay.

the class DataTableRenderer method encodeHeader.

protected void encodeHeader(FacesContext facesContext, ResponseWriter responseWriter, DataTable dataTable, DataTableInfo dataTableInfo) throws IOException {
    UIComponent headerFacet = dataTable.getFacet("header");
    if ((headerFacet != null) || dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
        responseWriter.startElement("thead", null);
        responseWriter.writeAttribute("class", "table-columns", null);
    }
    int totalRenderedColumns = dataTableInfo.getTotalRenderedColumns();
    int colspan = totalRenderedColumns;
    String selectionMode = dataTable.getSelectionMode();
    if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
        colspan++;
    }
    String headerClass = dataTable.getHeaderClass();
    if (headerFacet != null) {
        responseWriter.startElement("tr", null);
        responseWriter.startElement("th", null);
        if (headerClass == null) {
            responseWriter.writeAttribute("class", "facet", "headerClass");
        } else {
            responseWriter.writeAttribute("class", headerClass.concat(" facet"), "headerClass");
        }
        if (totalRenderedColumns > 1) {
            responseWriter.writeAttribute("colspan", colspan, null);
        }
        responseWriter.writeAttribute("scope", "colgroup", null);
        encodeRecurse(facesContext, headerFacet);
        responseWriter.endElement("th");
        responseWriter.endElement("tr");
    }
    if (dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
        responseWriter.startElement("tr", null);
        List<UIComponent> children = dataTable.getChildren();
        if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
            responseWriter.startElement("th", null);
            if ("checkbox".equals(selectionMode)) {
                responseWriter.startElement("input", null);
                String checkboxClientId = dataTable.getClientId(facesContext).concat("_selectAll");
                responseWriter.writeAttribute("id", checkboxClientId, null);
                responseWriter.writeAttribute("type", "checkbox", null);
                responseWriter.endElement("input");
            }
            responseWriter.endElement("th");
        }
        for (UIComponent child : children) {
            if (child instanceof UIColumn) {
                UIColumn uiColumn = (UIColumn) child;
                if (uiColumn.isRendered()) {
                    responseWriter.startElement("th", null);
                    if (child instanceof HtmlColumn) {
                        HtmlColumn htmlColumn = (HtmlColumn) child;
                        String columnHeaderClass = htmlColumn.getHeaderClass();
                        String sortClass = null;
                        Column alloyColumn = null;
                        if (child instanceof Column) {
                            alloyColumn = (Column) htmlColumn;
                            String sortOrder = alloyColumn.getSortOrder();
                            if ("ASCENDING".equals(sortOrder)) {
                                sortClass = " table-sortable-column table-sorted";
                            } else if ("DESCENDING".equals(sortOrder)) {
                                sortClass = " table-sortable-column table-sorted table-sorted-desc";
                            }
                        }
                        if (columnHeaderClass != null) {
                            if (sortClass != null) {
                                columnHeaderClass = columnHeaderClass.concat(sortClass);
                            }
                            responseWriter.writeAttribute("class", columnHeaderClass, "columnHeaderClass");
                        } else if (headerClass != null) {
                            if (sortClass != null) {
                                headerClass = headerClass.concat(sortClass);
                            }
                            responseWriter.writeAttribute("class", headerClass, "headerClass");
                        } else if (sortClass != null) {
                            responseWriter.writeAttribute("class", sortClass, null);
                        }
                        responseWriter.writeAttribute("scope", "col", null);
                        if (alloyColumn != null) {
                            String headerText = alloyColumn.getHeaderText();
                            if (headerText != null) {
                                encodeHeaderText(facesContext, responseWriter, dataTable, alloyColumn, headerText);
                            }
                        }
                        UIComponent columnHeaderFacet = htmlColumn.getFacet("header");
                        if (columnHeaderFacet != null) {
                            encodeRecurse(facesContext, columnHeaderFacet);
                        }
                    }
                    responseWriter.endElement("th");
                }
            }
        }
        responseWriter.endElement("tr");
    }
    if ((headerFacet != null) || dataTableInfo.isHeaderFacetOrTextPresentInColumn()) {
        responseWriter.endElement("thead");
    }
}
Also used : UIColumn(javax.faces.component.UIColumn) HtmlColumn(javax.faces.component.html.HtmlColumn) UIColumn(javax.faces.component.UIColumn) Column(com.liferay.faces.alloy.component.column.Column) UIComponent(javax.faces.component.UIComponent) HtmlColumn(javax.faces.component.html.HtmlColumn)

Example 4 with UIColumn

use of javax.faces.component.UIColumn in project liferay-faces-alloy by liferay.

the class DataEncoderBase method encodeColumns.

public void encodeColumns(FacesContext facesContext, UIData uiData, boolean iterateOverDataModel) throws IOException {
    if (iterateOverDataModel) {
        int rowCount = uiData.getRowCount();
        UIColumn prototypeChild = getPrototypeColumnChild(uiData);
        if (prototypeChild != null) {
            for (int i = 0; i < rowCount; i++) {
                uiData.setRowIndex(i);
                encodeColumn(facesContext, uiData, prototypeChild, i);
            }
        } else {
            String dataComponentName = getComponentName(uiData);
            Class<? extends UIColumn> columnClass = getColumnClass();
            String columnComponentName = getComponentName(columnClass);
            logger.warn("Unable to iterate because alloy:{0} does not have an alloy:{1} child element.", dataComponentName, columnComponentName);
        }
    } else {
        List<UIComponent> children = uiData.getChildren();
        for (int i = 0; i < children.size(); i++) {
            UIComponent child = children.get(i);
            Class<? extends UIColumn> columnClass = getColumnClass();
            if (columnClass.isInstance(child)) {
                encodeColumn(facesContext, uiData, columnClass.cast(child), i);
            } else {
                String dataComponentName = getComponentName(uiData);
                String columnComponentName = getComponentName(columnClass);
                logger.warn("Unable to render child element of alloy:{0} since it is not alloy:{1}", dataComponentName, columnComponentName);
            }
        }
    }
    uiData.setRowIndex(-1);
}
Also used : UIColumn(javax.faces.component.UIColumn) UIComponent(javax.faces.component.UIComponent)

Example 5 with UIColumn

use of javax.faces.component.UIColumn in project liferay-faces-alloy by liferay.

the class DataEncoderBase method getPrototypeColumnChild.

private UIColumn getPrototypeColumnChild(UIData uiData) {
    UIColumn prototypeChild = null;
    int childCount = uiData.getChildCount();
    if (childCount > 0) {
        List<UIComponent> children = uiData.getChildren();
        for (int i = 0; i < childCount; i++) {
            UIComponent child = children.get(i);
            Class<? extends UIColumn> columnClass = getColumnClass();
            if (columnClass.isInstance(child)) {
                prototypeChild = columnClass.cast(child);
            }
        }
    }
    return prototypeChild;
}
Also used : UIColumn(javax.faces.component.UIColumn) UIComponent(javax.faces.component.UIComponent)

Aggregations

UIColumn (javax.faces.component.UIColumn)5 UIComponent (javax.faces.component.UIComponent)4 Columns (org.primefaces.component.columns.Columns)2 Column (com.liferay.faces.alloy.component.column.Column)1 UIData (javax.faces.component.UIData)1 HtmlColumn (javax.faces.component.html.HtmlColumn)1 DynamicColumn (org.primefaces.component.api.DynamicColumn)1 UITreeNode (org.primefaces.component.tree.UITreeNode)1 SearchExpressionHint (org.primefaces.expression.SearchExpressionHint)1 CheckboxTreeNode (org.primefaces.model.CheckboxTreeNode)1 TreeNode (org.primefaces.model.TreeNode)1