@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { DataTable table = (DataTable) component; if (table.shouldEncodeFeature(context)) { for (Iterator<DataTableFeature> it = DataTable.FEATURES.values().iterator(); it.hasNext(); ) { DataTableFeature feature = it.next(); if (feature.shouldEncode(context, table)) { feature.encode(context, this, table); } } } else { if (table.isLazy()) { if (table.isLiveScroll()) table.loadLazyScrollData(0, table.getScrollRows()); else table.loadLazyData(); } encodeMarkup(context, table); encodeScript(context, table); } }
protected void encodeScript(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = table.getClientId(context); String selectionMode = table.resolveSelectionMode(); WidgetBuilder wb = getWidgetBuilder(context); wb.widget("DataTable", table.resolveWidgetVar(), clientId, true); // Pagination if (table.isPaginator()) { encodePaginatorConfig(context, table, wb); } // Selection wb.attr("selectionMode", selectionMode, null); // Filtering if (table.isFilteringEnabled()) { wb.attr("filter", true) .attr("filterEvent", table.getFilterEvent(), null) .attr("filterDelay", table.getFilterDelay(), Integer.MAX_VALUE); } // Row expansion if (table.getRowExpansion() != null) { wb.attr("expansion", true); } // Scrolling if (table.isScrollable()) { wb.attr("scrollable", true) .attr("liveScroll", table.isLiveScroll()) .attr("scrollStep", table.getScrollRows()) .attr("scrollLimit", table.getRowCount()) .attr("scrollWidth", table.getScrollWidth(), null) .attr("scrollHeight", table.getScrollHeight(), null); } // Resizable/Draggable Columns wb.attr("resizableColumns", table.isResizableColumns(), false) .attr("liveResize", table.isLiveResize(), false) .attr("draggableColumns", table.isDraggableColumns(), false); // Editing if (table.isEditable()) { wb.attr("editable", true) .attr("editMode", table.getEditMode()) .attr("cellSeparator", table.getCellSeparator(), null); } // MultiColumn Sorting if (table.isMultiSort()) { wb.attr("multiSort", true); } // Behaviors encodeClientBehaviors(context, table, wb); startScript(writer, clientId); writer.write(wb.build()); endScript(writer); }
public void encodeTbody(FacesContext context, DataTable table, boolean dataOnly) throws IOException { ResponseWriter writer = context.getResponseWriter(); String rowIndexVar = table.getRowIndexVar(); String clientId = table.getClientId(context); String emptyMessage = table.getEmptyMessage(); UIComponent emptyFacet = table.getFacet("emptyMessage"); SubTable subTable = table.getSubTable(); SummaryRow summaryRow = table.getSummaryRow(); if (table.isSelectionEnabled()) { table.findSelectedRowKeys(); } int rows = table.getRows(); int first = table.getFirst(); int rowCount = table.getRowCount(); int rowCountToRender = rows == 0 ? (table.isLiveScroll() ? table.getScrollRows() : rowCount) : rows; boolean hasData = rowCount > 0; if (!dataOnly) { writer.startElement("tbody", null); writer.writeAttribute("id", clientId + "_data", null); writer.writeAttribute("class", DataTable.DATA_CLASS, null); } if (hasData) { for (int i = first; i < (first + rowCountToRender); i++) { if (subTable != null) { encodeSubTable(context, table, subTable, i, rowIndexVar); } else { table.setRowIndex(i); if (!table.isRowAvailable()) { break; } encodeRow(context, table, clientId, i, rowIndexVar); if (summaryRow != null && !isInSameGroup(context, table, i)) { table.setRowIndex(i); // restore encodeSummaryRow(context, table, summaryRow); } } } } else { // Empty message writer.startElement("tr", null); writer.writeAttribute("class", DataTable.EMPTY_MESSAGE_ROW_CLASS, null); writer.startElement("td", null); writer.writeAttribute("colspan", table.getColumnsCount(), null); if (emptyFacet != null) emptyFacet.encodeAll(context); else writer.write(emptyMessage); writer.endElement("td"); writer.endElement("tr"); } if (!dataOnly) { writer.endElement("tbody"); } // Cleanup table.setRowIndex(-1); if (rowIndexVar != null) { context.getExternalContext().getRequestMap().remove(rowIndexVar); } }