org.icefaces.ace.component.datatable.DataTableRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of icefaces-ace Show documentation
Show all versions of icefaces-ace Show documentation
The advanced component library for ICEfaces.
/*
* Original Code Copyright Prime Technology.
* Subsequent Code Modifications Copyright 2011-2012 ICEsoft Technologies Canada Corp. (c)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NOTE THIS CODE HAS BEEN MODIFIED FROM ORIGINAL FORM
*
* Subsequent Code Modifications have been made and contributed by ICEsoft Technologies Canada Corp. (c).
*
* Code Modification 1: Integrated with ICEfaces Advanced Component Environment.
* Contributors: ICEsoft Technologies Canada Corp. (c)
*
* Code Modification 2: Improved Scrollable DataTable Column Sizing - ICE-7028
* Contributors: Nils Lundquist
*/
package org.icefaces.ace.component.datatable;
import org.icefaces.ace.component.celleditor.CellEditor;
import org.icefaces.ace.component.column.Column;
import org.icefaces.ace.component.columngroup.ColumnGroup;
import org.icefaces.ace.component.panelexpansion.PanelExpansion;
import org.icefaces.ace.component.row.Row;
import org.icefaces.ace.component.rowexpansion.RowExpansion;
import org.icefaces.ace.component.tableconfigpanel.TableConfigPanel;
import org.icefaces.ace.model.table.*;
import org.icefaces.ace.renderkit.CoreRenderer;
import org.icefaces.ace.util.ComponentUtils;
import org.icefaces.ace.util.HTML;
import org.icefaces.ace.util.JSONBuilder;
import org.icefaces.render.MandatoryResourceComponent;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.model.DataModel;
import javax.faces.model.SelectItem;
import java.io.IOException;
import java.util.*;
@MandatoryResourceComponent(tagName="dataTable", value="org.icefaces.ace.component.datatable.DataTable")
public class DataTableRenderer extends CoreRenderer {
@Override
public void decode(FacesContext context, UIComponent component) {
DataTable table = (DataTable) component;
// Deferred selection may occur on any request
if (table.isSelectionEnabled())
DataTableDecoder.decodeSelection(context, table);
// Other features will occurs as individual requests
if (table.isFilterRequest(context))
DataTableDecoder.decodeFilters(context, table);
else if (table.isSortRequest(context))
DataTableDecoder.decodeSortRequest(context, table, null, null);
else if (table.isPaginationRequest(context))
DataTableDecoder.decodePageRequest(context, table);
else if (table.isColumnReorderRequest(context))
DataTableDecoder.decodeColumnReorderRequest(context, table);
else if (table.isTableConfigurationRequest(context))
DataTableDecoder.decodeTableConfigurationRequest(context, table);
decodeBehaviors(context, component);
}
@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {}
@Override
public boolean getRendersChildren() { return true; }
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException{
DataTable table = (DataTable) component;
if (table.isPaginator())
table.calculatePage();
if (table.isSortOrderChanged())
table.processSorting();
if (table.isFilterValueChanged())
table.setFilteredData(table.processFilters(context));
// Force regeneration of data model pre-render
table.setModel(null);
if (table.isScrollingRequest(context))
encodeLiveRows(context, table);
else
encodeEntirety(context, table);
}
private void encodeEntirety(FacesContext context, DataTable table) throws IOException{
ResponseWriter writer = context.getResponseWriter();
String clientId = table.getClientId(context);
String style = null;
String styleClass;
String paginatorPosition = table.getPaginatorPosition();
String containerClass = DataTableConstants.CONTAINER_CLASS;
boolean hasPaginator = table.isPaginator();
boolean staticHeaders = table.isScrollable() && table.isStaticHeaders();
table.getStateMap(); // init statemap while row index == -1
if (staticHeaders)
containerClass += " " + DataTableConstants.SCROLLABLE_CONTAINER_CLASS;
if ((styleClass = table.getStyleClass()) != null)
containerClass += " " + styleClass;
writer.startElement(HTML.DIV_ELEM, table);
writer.writeAttribute(HTML.ID_ATTR, clientId, HTML.ID_ATTR);
writer.writeAttribute(HTML.CLASS_ATTR, containerClass, "styleClass");
if ((style = table.getStyle()) != null)
writer.writeAttribute(HTML.STYLE_ELEM, style, HTML.STYLE_ELEM);
encodeFacet(context, table, table.getHeader(), DataTableConstants.HEADER_CLASS);
if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom"))
encodePaginatorMarkup(context, table, "top");
encodeConfigPanel(context, table);
encodeTable(context, table, staticHeaders);
if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top"))
encodePaginatorMarkup(context, table, "bottom");
encodeFacet(context, table, table.getFooter(), DataTableConstants.FOOTER_CLASS);
if (table.isSelectionEnabled())
encodeSelectionAndDeselectionHolder(context, table);
encodeScript(context, table);
// Avoid sharing cached stateMap with other iterative instances
table.clearCachedStateMap();
if ("true".equals(context.getExternalContext().getInitParameter("ForceFullTableDOMUpdates"))) {
writer.startElement(HTML.DIV_ELEM, null);
writer.writeAttribute(HTML.STYLE_ATTR, "display:none;",null);
writer.writeText(table.getForcedUpdateCounter(), null);
writer.endElement(HTML.DIV_ELEM);
}
writer.endElement(HTML.DIV_ELEM);
}
private void encodeTable(FacesContext context, DataTable table, boolean staticHeaders) throws IOException {
ResponseWriter writer = context.getResponseWriter();
List columns = table.getColumns();
if (!staticHeaders) {
Integer height;
writer.startElement(HTML.DIV_ELEM, null);
if (table.isScrollable() && (height = table.getScrollHeight()) != null)
writer.writeAttribute(HTML.STYLE_ELEM, "max-height:" + height + "px; overflow:auto;", null);
writer.startElement(HTML.TABLE_ELEM, null);
}
DataTableHeadRenderer.encodeTableHead(context, table, columns, staticHeaders);
encodeTableBody(context, table, columns, staticHeaders);
DataTableFootRenderer.encodeTableFoot(context, table, columns, staticHeaders);
if (!staticHeaders) {
writer.endElement(HTML.TABLE_ELEM);
writer.endElement(HTML.DIV_ELEM);
}
}
private void encodeTableBody(FacesContext context, DataTable table, List columns, boolean scrollable) throws IOException {
ResponseWriter writer = context.getResponseWriter();
String rowIndexVar = table.getRowIndexVar();
String clientId = table.getClientId(context);
if (scrollable) {
writer.startElement(HTML.DIV_ELEM, null);
String scrollClass = DataTableConstants.SCROLLABLE_X_CLASS + " " + DataTableConstants.SCROLLABLE_BODY_CLASS;
writer.writeAttribute(HTML.CLASS_ATTR, scrollClass, null);
writer.writeAttribute(HTML.STYLE_ELEM, "max-height:" + table.getScrollHeight() + "px", null);
writer.startElement(HTML.TABLE_ELEM, null);
if (table.hasHeaders()) {
table.setInDuplicateSegment(true);
DataTableHeadRenderer.encodeTableHead(context, table, columns, false);
table.setInDuplicateSegment(false);
}
}
if (table.isLazy()) table.loadLazyData();
int rows = table.getRows();
int first = table.getFirst();
int page = table.getPage();
int rowCount = table.getRowCount();
int rowCountToRender = rows == 0 ? rowCount : rows;
boolean renderedTopVisible = false;
boolean hasData = rowCount > 0;
String tbodyClass = hasData ? DataTableConstants.DATA_CLASS : DataTableConstants.EMPTY_DATA_CLASS;
writer.startElement(HTML.TBODY_ELEM, null);
writer.writeAttribute(HTML.CLASS_ATTR, tbodyClass, null);
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy