protected void encodeScrollableTable(FacesContext context, DataTable table) throws IOException { String tableStyle = table.getStyle(); String tableStyleClass = table.getStyleClass(); encodeScrollAreaStart( context, table, DataTable.SCROLLABLE_HEADER_CLASS, DataTable.SCROLLABLE_HEADER_BOX_CLASS, tableStyle, tableStyleClass); encodeThead(context, table); encodeScrollAreaEnd(context); encodeScrollBody(context, table, tableStyle, tableStyleClass); encodeScrollAreaStart( context, table, DataTable.SCROLLABLE_FOOTER_CLASS, DataTable.SCROLLABLE_FOOTER_BOX_CLASS, tableStyle, tableStyleClass); encodeTFoot(context, table); encodeScrollAreaEnd(context); }
protected void encodeFrozenRows(FacesContext context, DataTable table) throws IOException { Collection<?> frozenRows = table.getFrozenRows(); if (frozenRows == null || frozenRows.isEmpty()) { return; } ResponseWriter writer = context.getResponseWriter(); String clientId = table.getClientId(context); String var = table.getVar(); String rowIndexVar = table.getRowIndexVar(); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); writer.startElement("tbody", null); writer.writeAttribute("class", DataTable.DATA_CLASS, null); int index = 0; for (Iterator<? extends Object> it = frozenRows.iterator(); it.hasNext(); ) { requestMap.put(var, it.next()); if (rowIndexVar != null) { requestMap.put(rowIndexVar, index); } encodeRow(context, table, clientId, index, rowIndexVar); } writer.endElement("tbody"); }
public void setupCurrentRowVariables() { if (_evaluatingConverterInsideSetupCurrentRowVariables) { // Prevent endless recursion in the column.getGroupingValueConverter() call (see below). // The grouping-related variables are not required during calculation of // groupingValueConverter, // so we can just skip this method if _evaluatingConverterInsideSetupCurrentRowVariables == // true return; } DataTable dataTable = getDataTable(); Object rowData = dataTable.isRowAvailable() ? dataTable.getRowData() : null; if (!(rowData instanceof GroupHeaderOrFooter)) { Components.setRequestVariable(getColumnHeaderVar(), null); Components.setRequestVariable(getGroupingValueVar(), null); Components.setRequestVariable(getGroupingValueStringVar(), null); return; } GroupHeaderOrFooter row = (GroupHeaderOrFooter) rowData; RowGroup rowGroup = row.getRowGroup(); String columnId = rowGroup.getColumnId(); Column column = (Column) dataTable.getColumnById(columnId); String columnHeader = column.getColumnHeader(); Components.setRequestVariable(getColumnHeaderVar(), columnHeader); Object groupingValue = rowGroup.getGroupingValue(); Components.setRequestVariable(getGroupingValueVar(), groupingValue); Converter groupingValueConverter; _evaluatingConverterInsideSetupCurrentRowVariables = true; // The upcoming getGroupingValueConverter call can invoke table's setRowIndex, which will result // re-entering this setupCurrentRowVariables method, so we should prevent endless recursion // here. try { groupingValueConverter = column.getGroupingValueConverter(); } finally { _evaluatingConverterInsideSetupCurrentRowVariables = false; } FacesContext context = FacesContext.getCurrentInstance(); if (groupingValueConverter == null) { groupingValueConverter = groupingValue != null ? Rendering.getConverterForType(context, groupingValue.getClass()) : null; } String groupingValueStr = groupingValueConverter != null ? groupingValueConverter.getAsString(context, column, groupingValue) : groupingValue != null ? groupingValue.toString() : ""; Components.setRequestVariable(getGroupingValueStringVar(), groupingValueStr); }
/** * This method reads all rows from the {@link #dataReader DataReader} object and adds them into * the {@link #dataTable DataTable} object. If the default behaviour is not sufficient or desired, * method should be overridden. * * @return the constructed datatable. * @throws CIlibIOException wraps another Exception that might occur during IO */ public DataTable buildDataTable() throws CIlibIOException { dataReader.open(); while (dataReader.hasNextRow()) { dataTable.addRow(dataReader.nextRow()); } dataTable.setColumnNames(dataReader.getColumnNames()); dataReader.close(); for (DataOperator operator : operatorPipeline) { this.setDataTable(operator.operate(this.getDataTable())); } return (DataTable) this.dataTable.getClone(); }
private void loadDrsInfo() throws Exception { long dataTableNo = readLongValue(); long firstFileOffset = readLongValue(); if (logger.isDebugEnabled()) { logger.debug("data table number:{}", dataTableNo); logger.debug("first file offset:{}", firstFileOffset); } List<DataTable> dataTables = new ArrayList<DataTable>(); for (int i = 0; i < dataTableNo; i++) { if (logger.isDebugEnabled()) { logger.debug("loading data table info ... ({}/{})", (i + 1), dataTableNo); } DataTable dt = new DataTable(); dataTables.add(dt); dt.dataType = readStringValue().trim(); dt.dataOffset = readLongValue(); dt.dataFileCount = readLongValue(); if (logger.isDebugEnabled()) { logger.debug("\tdata type:{}", dt.dataType); logger.debug("\tdata offset:{}", dt.dataOffset); logger.debug("\tdata file count:{}", dt.dataFileCount); } } for (DataTable dt : dataTables) { for (int i = 0; i < dt.dataFileCount; i++) { if (logger.isDebugEnabled()) { logger.debug( "loading data file ({}) info ... ({}/{})", dt.dataType, (i + 1), dt.dataFileCount); } FileInfo fi = new FileInfo(); fi.fileNo = readLongValue(); fi.offset = readLongValue(); fi.len = (int) readLongValue(); dataFiles.put(fi.fileNo, fi); if (logger.isDebugEnabled()) { logger.debug("\tfile number:{}", fi.fileNo); logger.debug("\tdata offset:{}", fi.offset); logger.debug("\tfile length:{}", fi.len); } } } }
/** * read the DataTable and convert it to a two dimentional array. * * @param table the table * @return the table array */ public final Object[][] getTableArray(final DataTable table) { Integer rowcount = table.getRowCount(); Integer colcount = table.getcolCount(); Object[][] tabArray = new Object[rowcount][colcount]; for (int row = 0; row < rowcount; row++) { for (int col = 0; col < colcount; col++) { tabArray[row][col] = table.get(row, col); } } return tabArray; }
boolean isInSameGroup(FacesContext context, DataTable table, int currentRowIndex) { table.setRowIndex(currentRowIndex); Object currentGroupByData = table.getSortBy(); table.setRowIndex(currentRowIndex + 1); if (!table.isRowAvailable()) return false; Object nextGroupByData = table.getSortBy(); if (currentGroupByData != null && nextGroupByData.equals(currentGroupByData)) { return true; } return false; }
protected void encodeRadio( FacesContext context, DataTable table, boolean checked, boolean disabled) throws IOException { ResponseWriter writer = context.getResponseWriter(); String boxClass = HTML.RADIOBUTTON_BOX_CLASS; String iconClass = HTML.RADIOBUTTON_ICON_CLASS; boxClass = disabled ? boxClass + " ui-state-disabled" : boxClass; boxClass = checked ? boxClass + " ui-state-active" : boxClass; iconClass = checked ? iconClass + " " + HTML.RADIOBUTTON_CHECKED_ICON_CLASS : iconClass; writer.startElement("div", null); writer.writeAttribute("class", HTML.RADIOBUTTON_CLASS, null); writer.startElement("div", null); writer.writeAttribute("class", "ui-helper-hidden-accessible", null); writer.startElement("input", null); writer.writeAttribute("type", "radio", null); writer.writeAttribute("name", table.getClientId(context) + "_radio", null); writer.endElement("input"); writer.endElement("div"); writer.startElement("div", null); writer.writeAttribute("class", boxClass, null); writer.startElement("span", null); writer.writeAttribute("class", iconClass, null); writer.endElement("span"); writer.endElement("div"); writer.endElement("div"); }
/** Render column headers either in single row or nested if a columnGroup is defined */ protected void encodeThead(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); ColumnGroup group = table.getColumnGroup("header"); writer.startElement("thead", null); writer.writeAttribute("id", table.getClientId(context) + "_head", null); if (group != null && group.isRendered()) { for (UIComponent child : group.getChildren()) { if (child.isRendered() && child instanceof Row) { Row headerRow = (Row) child; writer.startElement("tr", null); for (UIComponent headerRowChild : headerRow.getChildren()) { if (headerRowChild.isRendered() && headerRowChild instanceof Column) { encodeColumnHeader(context, table, (Column) headerRowChild); } } writer.endElement("tr"); } } } else { writer.startElement("tr", null); writer.writeAttribute("role", "row", null); for (UIColumn column : table.getColumns()) { if (column instanceof Column) { encodeColumnHeader(context, table, column); } else if (column instanceof DynamicColumn) { DynamicColumn dynamicColumn = (DynamicColumn) column; dynamicColumn.applyModel(); encodeColumnHeader(context, table, dynamicColumn); } } writer.endElement("tr"); } encodeFrozenRows(context, table); writer.endElement("thead"); }
protected void encodeSummaryRow(FacesContext context, DataTable table, SummaryRow summaryRow) throws IOException { MethodExpression me = summaryRow.getListener(); if (me != null) { me.invoke(context.getELContext(), new Object[] {table.getSortBy()}); } summaryRow.encodeAll(context); }
public XmlData toXmlData() { XmlData xd = new XmlData(); for (DataColumn dc : belongToDT.getColumns()) { String n = dc.getName(); Object o = this.getValue(n); if (o != null) xd.setParamValue(n, o); } return xd; }
protected void encodeTFoot(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); ColumnGroup group = table.getColumnGroup("footer"); writer.startElement("tfoot", null); if (group != null && group.isRendered()) { for (UIComponent child : group.getChildren()) { if (child.isRendered() && child instanceof Row) { Row footerRow = (Row) child; writer.startElement("tr", null); for (UIComponent footerRowChild : footerRow.getChildren()) { if (footerRowChild.isRendered() && footerRowChild instanceof Column) { encodeColumnFooter(context, table, (Column) footerRowChild); } } writer.endElement("tr"); } } } else if (table.hasFooterColumn()) { writer.startElement("tr", null); for (UIColumn column : table.getColumns()) { if (column instanceof Column) { encodeColumnFooter(context, table, column); } else if (column instanceof DynamicColumn) { DynamicColumn dynamicColumn = (DynamicColumn) column; dynamicColumn.applyModel(); encodeColumnFooter(context, table, dynamicColumn); } } writer.endElement("tr"); } writer.endElement("tfoot"); }
protected void encodeSubTable( FacesContext context, DataTable table, SubTable subTable, int rowIndex, String rowIndexVar) throws IOException { table.setRowIndex(rowIndex); if (!table.isRowAvailable()) { return; } // Row index var if (rowIndexVar != null) { context.getExternalContext().getRequestMap().put(rowIndexVar, rowIndex); } subTable.encodeAll(context); if (rowIndexVar != null) { context.getExternalContext().getRequestMap().remove(rowIndexVar); } }
public void putValue(int idx, Object ov) { String n = belongToDT.getColumnName(idx); if (n == null) throw new RuntimeException("no coloumn found with index=" + idx); if (ov != null) { if ((ov instanceof java.util.Date) && !(ov instanceof java.sql.Timestamp)) { ov = new java.sql.Timestamp(((java.util.Date) ov).getTime()); } this.put(n, ov); } else this.remove(n); }
public void encodeColGroup(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("colgroup", null); for (UIColumn column : table.getColumns()) { if (column.isRendered()) { writer.startElement("col", null); writer.endElement("col"); } } writer.endElement("colgroup"); }
protected void encodeRowExpansion(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); int expandedRowIndex = Integer.parseInt(params.get(table.getClientId(context) + "_expandedRowIndex")); String rowIndexVar = table.getRowIndexVar(); table.setRowIndex(expandedRowIndex); if (rowIndexVar != null) { context.getExternalContext().getRequestMap().put(rowIndexVar, expandedRowIndex); } writer.startElement("tr", null); writer.writeAttribute("style", "display:none", null); writer.writeAttribute( "class", DataTable.EXPANDED_ROW_CONTENT_CLASS + " ui-widget-content", null); writer.startElement("td", null); writer.writeAttribute("colspan", table.getColumnsCount(), null); table.getRowExpansion().encodeAll(context); writer.endElement("td"); writer.endElement("tr"); table.setRowIndex(-1); }
public void fromXmlData(XmlData xd) { for (DataColumn dc : belongToDT.getColumns()) { String n = dc.getName(); Object ov = xd.getParamValue(n); if (ov != null) { // 适应jdbc数据库访问要求 if ((ov instanceof java.util.Date) && !(ov instanceof java.sql.Timestamp)) { ov = new java.sql.Timestamp(((java.util.Date) ov).getTime()); } this.put(n, ov); } } }
public void acceptNewGroupingRules(List<GroupingRule> groupingRules) { if (beforeUpdateValuesPhase) { incomingGroupingRules = groupingRules; return; } DataTable dataTable = getDataTable(); for (GroupingRule sortingRule : groupingRules) { String columnId = sortingRule.getColumnId(); BaseColumn column = dataTable.getColumnById(columnId); if (column == null) throw new IllegalArgumentException("Column by id not found: " + columnId); if (!column.isColumnGroupable()) throw new IllegalArgumentException( "Column (id = " + columnId + ") is not groupable. Column class is " + column.getClass() + " ; specify sortingExpression or groupingExpression for <o:column> to " + "make it groupable"); } setGroupingRules(groupingRules); }
public void putKeysToTable() throws IOException { long fileLength = dataFile.length(); int j = 0; if (!offsets.isEmpty()) { int offsetsSize = offsets.size(); while (j < offsetsSize) { byte[] b = new byte[offsets.get(j)]; inStream.read(b, 0, offsets.get(j)); dataTable.put(keysToMap.get(j), new String(b, StandardCharsets.UTF_8)); curPos += offsets.get(j); ++j; } } if (curPos < fileLength) { int lastOffset = (int) (fileLength - curPos); byte[] b = new byte[lastOffset]; for (int k = 0; curPos < fileLength; ++k, ++curPos) { b[k] = inStream.readByte(); } dataTable.put(keysToMap.get(j), new String(b, StandardCharsets.UTF_8)); } dataTable.commit(); }
protected void encodeScrollBody( FacesContext context, DataTable table, String tableStyle, String tableStyleClass) throws IOException { ResponseWriter writer = context.getResponseWriter(); String scrollHeight = table.getScrollHeight(); writer.startElement("div", null); writer.writeAttribute("class", DataTable.SCROLLABLE_BODY_CLASS, null); if (scrollHeight != null && scrollHeight.indexOf("%") == -1) { writer.writeAttribute("style", "height:" + scrollHeight + "px", null); } writer.startElement("table", null); writer.writeAttribute("role", "grid", null); if (tableStyle != null) writer.writeAttribute("style", tableStyle, null); if (table.getTableStyleClass() != null) writer.writeAttribute("class", tableStyleClass, null); encodeColGroup(context, table); encodeTbody(context, table, false); writer.endElement("table"); writer.endElement("div"); }
public static void main(String[] args) { // Create a Connector object and open the connection to the server Connector server = new Connector(); boolean success = server.connect("MNP", "0a34d4ea3cc0da36ee91172b9cccb621"); if (success == false) { System.out.println("Fatal error: could not open connection to server"); System.exit(1); } DataTable data = server.getData(); int rowCount = data.getRowCount(); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < 4; ++col) { if (col > 0) { System.out.print(","); } System.out.print(data.getCell(row, col)); } System.out.println(); } }
public void testGetTableForName() { DataTable table1 = response1.getTableForName("Results"); assertEquals(0, table1.getRowCount()); DataTable table31 = response3.getTableForName("Results"); assertEquals(2, table31.getRowCount()); DataTable table32 = response3.getTableForName("Simple"); assertEquals(1, table32.getRowCount()); }
@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 encodeRegularTable(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("div", null); writer.writeAttribute("class", DataTable.TABLE_WRAPPER_CLASS, null); writer.startElement("table", null); writer.writeAttribute("role", "grid", null); if (table.getTableStyle() != null) writer.writeAttribute("style", table.getTableStyle(), null); if (table.getTableStyleClass() != null) writer.writeAttribute("class", table.getTableStyleClass(), null); if (table.getSummary() != null) writer.writeAttribute("summary", table.getSummary(), null); encodeThead(context, table); encodeTFoot(context, table); encodeTbody(context, table, false); writer.endElement("table"); writer.endElement("div"); }
protected void encodeMarkup(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = table.getClientId(context); boolean scrollable = table.isScrollable(); boolean hasPaginator = table.isPaginator(); String style = table.getStyle(); String paginatorPosition = table.getPaginatorPosition(); // style class String containerClass = scrollable ? DataTable.CONTAINER_CLASS + " " + DataTable.SCROLLABLE_CONTAINER_CLASS : DataTable.CONTAINER_CLASS; containerClass = table.getStyleClass() != null ? containerClass + " " + table.getStyleClass() : containerClass; if (table.isResizableColumns()) containerClass = containerClass + " " + DataTable.RESIZABLE_CONTAINER_CLASS; if (ComponentUtils.isRTL(context, table)) containerClass = containerClass + " " + DataTable.RTL_CLASS; // default sort if (!table.isDefaultSorted() && table.getSortBy() != null && !table.isLazy()) { SortFeature sortFeature = (SortFeature) table.getFeature(DataTableFeatureKey.SORT); if (table.isMultiSort()) sortFeature.multiSort(context, table); else sortFeature.singleSort(context, table); table.setDefaultSorted(); } if (hasPaginator) { table.calculateFirst(); } writer.startElement("div", table); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", containerClass, "styleClass"); if (style != null) { writer.writeAttribute("style", style, "style"); } encodeFacet(context, table, table.getHeader(), DataTable.HEADER_CLASS); if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom")) { encodePaginatorMarkup(context, table, "top"); } if (scrollable) { encodeScrollableTable(context, table); } else { encodeRegularTable(context, table); } if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top")) { encodePaginatorMarkup(context, table, "bottom"); } encodeFacet(context, table, table.getFooter(), DataTable.FOOTER_CLASS); if (table.isSelectionEnabled()) { encodeStateHolder( context, table, table.getClientId(context) + "_selection", table.getSelectedRowKeysAsString()); } if (table.isDraggableColumns()) { encodeStateHolder(context, table, table.getClientId(context) + "_columnOrder", null); } if (scrollable) { encodeStateHolder( context, table, table.getClientId(context) + "_scrollState", table.getScrollState()); } writer.endElement("div"); }
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 boolean encodeRow( FacesContext context, DataTable table, String clientId, int rowIndex, String rowIndexVar) throws IOException { ResponseWriter writer = context.getResponseWriter(); boolean selectionEnabled = table.isSelectionEnabled(); Object rowKey = null; if (selectionEnabled) { // try rowKey attribute rowKey = table.getRowKey(); // ask selectable datamodel if (rowKey == null) rowKey = table.getRowKeyFromModel(table.getRowData()); } // Preselection boolean selected = table.getSelectedRowKeys().contains(rowKey); String userRowStyleClass = table.getRowStyleClass(); String rowStyleClass = rowIndex % 2 == 0 ? DataTable.ROW_CLASS + " " + DataTable.EVEN_ROW_CLASS : DataTable.ROW_CLASS + " " + DataTable.ODD_ROW_CLASS; if (selected) { rowStyleClass = rowStyleClass + " ui-state-highlight"; } if (userRowStyleClass != null) { rowStyleClass = rowStyleClass + " " + userRowStyleClass; } if (table.isEditingRow()) { rowStyleClass = rowStyleClass + " " + DataTable.EDITING_ROW_CLASS; } writer.startElement("tr", null); writer.writeAttribute("data-ri", rowIndex, null); if (rowKey != null) { writer.writeAttribute("data-rk", rowKey, null); } writer.writeAttribute("class", rowStyleClass, null); writer.writeAttribute("role", "row", null); if (selectionEnabled) { writer.writeAttribute("aria-selected", String.valueOf(selected), null); } for (UIColumn column : table.getColumns()) { if (column instanceof Column) { encodeCell(context, table, column, clientId, selected); } else if (column instanceof DynamicColumn) { DynamicColumn dynamicColumn = (DynamicColumn) column; dynamicColumn.applyModel(); encodeCell(context, table, dynamicColumn, null, false); } } writer.endElement("tr"); return true; }
protected void encodeColumnHeader(FacesContext context, DataTable table, UIColumn column) throws IOException { if (!column.isRendered()) { return; } ResponseWriter writer = context.getResponseWriter(); String clientId = column.getContainerClientId(context); Object tableSortBy = table.getSortBy(); Object columnSortBy = column.getSortBy(); boolean isSortable = columnSortBy != null; boolean hasFilter = column.getFilterBy() != null; String selectionMode = column.getSelectionMode(); String sortIcon = null; boolean resizable = table.isResizableColumns() && column.isResizable(); String columnClass = isSortable ? DataTable.COLUMN_HEADER_CLASS + " " + DataTable.SORTABLE_COLUMN_CLASS : DataTable.COLUMN_HEADER_CLASS; columnClass = hasFilter ? columnClass + " " + DataTable.FILTER_COLUMN_CLASS : columnClass; columnClass = selectionMode != null ? columnClass + " " + DataTable.SELECTION_COLUMN_CLASS : columnClass; columnClass = resizable ? columnClass + " " + DataTable.RESIZABLE_COLUMN_CLASS : columnClass; columnClass = column.getStyleClass() != null ? columnClass + " " + column.getStyleClass() : columnClass; if (isSortable) { if (tableSortBy != null) { if (table.isMultiSort()) { List<SortMeta> sortMeta = table.getMultiSortMeta(); if (sortMeta != null) { for (SortMeta meta : sortMeta) { sortIcon = resolveDefaultSortIcon( columnSortBy, meta.getColumn().getSortBy(), meta.getSortOrder().name()); if (sortIcon != null) { break; } } } } else { sortIcon = resolveDefaultSortIcon(columnSortBy, tableSortBy, table.getSortOrder()); } } if (sortIcon == null) sortIcon = DataTable.SORTABLE_COLUMN_ICON_CLASS; else columnClass += " ui-state-active"; } String style = column.getStyle(); String width = column.getWidth(); if (width != null) { String unit = width.endsWith("%") ? "" : "px"; if (style != null) style = style + ";width:" + width + unit; else style = "width:" + width + unit; } writer.startElement("th", null); writer.writeAttribute("id", clientId, null); writer.writeAttribute("class", columnClass, null); writer.writeAttribute("role", "columnheader", null); if (style != null) writer.writeAttribute("style", style, null); if (column.getRowspan() != 1) writer.writeAttribute("rowspan", column.getRowspan(), null); if (column.getColspan() != 1) writer.writeAttribute("colspan", column.getColspan(), null); if (hasFilter) { table.enableFiltering(); String filterPosition = column.getFilterPosition(); if (filterPosition.equals("bottom")) { encodeColumnHeaderContent(context, column, sortIcon); encodeFilter(context, table, column); } else if (filterPosition.equals("top")) { encodeFilter(context, table, column); encodeColumnHeaderContent(context, column, sortIcon); } else { throw new FacesException( filterPosition + " is an invalid option for filterPosition, valid values are 'bottom' or 'top'."); } } else { encodeColumnHeaderContent(context, column, sortIcon); } if (selectionMode != null && selectionMode.equalsIgnoreCase("multiple")) { encodeCheckbox(context, table, false, column.isDisabledSelection(), HTML.CHECKBOX_ALL_CLASS); } writer.endElement("th"); }
protected void encodeFilter(FacesContext context, DataTable table, UIColumn column) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ResponseWriter writer = context.getResponseWriter(); String separator = String.valueOf(UINamingContainer.getSeparatorChar(context)); String filterId = column.getContainerClientId(context) + separator + "filter"; String filterStyleClass = column.getFilterStyleClass(); String filterValue = null; if (table.isReset()) { filterValue = ""; } else { if (params.containsKey(filterId)) { filterValue = params.get(filterId); } else { ValueExpression filterValueVE = column.getValueExpression("filterValue"); if (filterValueVE != null) { filterValue = (String) filterValueVE.getValue(context.getELContext()); } else { filterValue = ""; } } } if (column.getValueExpression("filterOptions") == null) { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_INPUT_FILTER_CLASS : DataTable.COLUMN_INPUT_FILTER_CLASS + " " + filterStyleClass; writer.startElement("input", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); writer.writeAttribute("value", filterValue, null); writer.writeAttribute("autocomplete", "off", null); if (column.getFilterStyle() != null) writer.writeAttribute("style", column.getFilterStyle(), null); if (column.getFilterMaxLength() != Integer.MAX_VALUE) writer.writeAttribute("maxlength", column.getFilterMaxLength(), null); writer.endElement("input"); } else { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_FILTER_CLASS : DataTable.COLUMN_FILTER_CLASS + " " + filterStyleClass; writer.startElement("select", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); SelectItem[] itemsArray = (SelectItem[]) getFilterOptions(column); for (SelectItem item : itemsArray) { Object itemValue = item.getValue(); writer.startElement("option", null); writer.writeAttribute("value", item.getValue(), null); if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) { writer.writeAttribute("selected", "selected", null); } writer.writeText(item.getLabel(), null); writer.endElement("option"); } writer.endElement("select"); } }
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); } }