Search in sources :

Example 1 with HtmlColumn

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

the class DataTableRenderer method encodeRow.

protected void encodeRow(FacesContext facesContext, ResponseWriter responseWriter, DataTable dataTable, int rowIndex, ItemCycler rowClasses, ItemCycler columnClasses) throws IOException {
    responseWriter.startElement("tr", dataTable);
    String rowClass = rowClasses.getNextItem();
    if (rowClass != null) {
        responseWriter.writeAttribute("class", rowClass, "rowClasses");
    }
    String selectionMode = dataTable.getSelectionMode();
    if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
        Set<String> selectedRowIndexSet = new HashSet<String>();
        String selectedRowIndexes = dataTable.getSelectedRowIndexes();
        if (selectedRowIndexes != null) {
            String[] selectedRowIndexArray = selectedRowIndexes.split(",");
            selectedRowIndexSet = new HashSet<String>(Arrays.asList(selectedRowIndexArray));
        }
        String rowIndexAsString = Integer.toString(rowIndex);
        if (selectedRowIndexSet.contains(rowIndexAsString)) {
            responseWriter.writeAttribute("class", "info", null);
        }
        responseWriter.startElement("td", null);
        responseWriter.startElement("input", null);
        String checkboxClientId = dataTable.getClientId(facesContext);
        responseWriter.writeAttribute("id", checkboxClientId, null);
        responseWriter.writeAttribute("type", selectionMode, null);
        if (selectedRowIndexSet.contains(rowIndexAsString)) {
            responseWriter.writeAttribute("checked", "checked", null);
        }
        responseWriter.endElement("input");
        responseWriter.endElement("td");
    }
    List<UIComponent> children = dataTable.getChildren();
    for (UIComponent child : children) {
        if (child instanceof HtmlColumn) {
            HtmlColumn htmlColumn = (HtmlColumn) child;
            if (htmlColumn.isRendered()) {
                if (htmlColumn.isRowHeader()) {
                    responseWriter.startElement("th", htmlColumn);
                    responseWriter.writeAttribute("scope", "row", null);
                } else {
                    responseWriter.startElement("td", htmlColumn);
                }
                String columnClass = columnClasses.getNextItem();
                if (columnClass != null) {
                    responseWriter.writeAttribute("class", columnClass, "columnClasses");
                }
                List<UIComponent> htmlColumnChildren = htmlColumn.getChildren();
                for (UIComponent htmlColumnChild : htmlColumnChildren) {
                    encodeRecurse(facesContext, htmlColumnChild);
                }
                if (htmlColumn.isRowHeader()) {
                    responseWriter.endElement("th");
                } else {
                    responseWriter.endElement("td");
                }
            }
        }
    }
    responseWriter.endElement("tr");
}
Also used : UIComponent(javax.faces.component.UIComponent) HashSet(java.util.HashSet) HtmlColumn(javax.faces.component.html.HtmlColumn)

Example 2 with HtmlColumn

use of javax.faces.component.html.HtmlColumn 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 3 with HtmlColumn

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

the class DataTableRenderer method encodeFooter.

protected void encodeFooter(FacesContext facesContext, ResponseWriter responseWriter, DataTable dataTable, DataTableInfo dataTableInfo) throws IOException {
    UIComponent footerFacet = dataTable.getFacet("footer");
    if ((footerFacet != null) || dataTableInfo.isFooterFacetPresentInColumn()) {
        responseWriter.startElement("tfoot", null);
    }
    String footerClass = dataTable.getFooterClass();
    if (dataTableInfo.isFooterFacetPresentInColumn()) {
        responseWriter.startElement("tr", null);
        List<UIComponent> children = dataTable.getChildren();
        for (UIComponent child : children) {
            if (child instanceof HtmlColumn) {
                HtmlColumn htmlColumn = (HtmlColumn) child;
                if (htmlColumn.isRendered()) {
                    responseWriter.startElement("td", null);
                    String columnFooterClass = htmlColumn.getFooterClass();
                    if (columnFooterClass != null) {
                        responseWriter.writeAttribute("class", columnFooterClass, "columnFooterClass");
                    } else if (footerClass != null) {
                        responseWriter.writeAttribute("class", footerClass, "footerClass");
                    }
                    UIComponent columnFooterFacet = htmlColumn.getFacet("footer");
                    if (columnFooterFacet != null) {
                        encodeRecurse(facesContext, columnFooterFacet);
                    }
                    responseWriter.endElement("td");
                }
            }
        }
        responseWriter.endElement("tr");
    }
    int totalRenderedColumns = dataTableInfo.getTotalRenderedColumns();
    int colspan = totalRenderedColumns;
    String selectionMode = dataTable.getSelectionMode();
    if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
        colspan++;
    }
    if (footerFacet != null) {
        responseWriter.startElement("tr", null);
        responseWriter.startElement("td", null);
        if (footerClass == null) {
            responseWriter.writeAttribute("class", "facet", "footerClass");
        } else {
            responseWriter.writeAttribute("class", footerClass.concat(" facet"), "footerClass");
        }
        if (totalRenderedColumns > 1) {
            responseWriter.writeAttribute("colspan", colspan, null);
        }
        encodeRecurse(facesContext, footerFacet);
        responseWriter.endElement("td");
        responseWriter.endElement("tr");
    }
    if ((footerFacet != null) || dataTableInfo.isFooterFacetPresentInColumn()) {
        responseWriter.endElement("tfoot");
    }
}
Also used : UIComponent(javax.faces.component.UIComponent) HtmlColumn(javax.faces.component.html.HtmlColumn)

Aggregations

UIComponent (javax.faces.component.UIComponent)3 HtmlColumn (javax.faces.component.html.HtmlColumn)3 Column (com.liferay.faces.alloy.component.column.Column)1 HashSet (java.util.HashSet)1 UIColumn (javax.faces.component.UIColumn)1