Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright ${year}, Red Hat, Inc. and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.richfaces.renderkit;
 
 
 import  javax.faces.application.ResourceDependencies;
 import  javax.faces.application.ResourceDependency;
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.context.ResponseWriter;
 

Author(s):
Anton Belevich
 
 @ResourceDependencies({ @ResourceDependency(name = "richfaces-event.js") })
 public abstract class AbstractTableRenderer extends AbstractTableBaseRenderer implements MetaComponentRenderer {
     public static final String HIDDEN_CONTAINER_ID = ":sc";
 
     public abstract EncodeStrategy getHiddenContainerStrategy(UIDataTableBase dataTableBase);
 
     public boolean isColumnAttributeSet(UIDataTableBase tableString attributeName) {
         Iterator<UIComponent> columns = table.columns();
         boolean result = false;
         while (columns.hasNext() && !result) {
             UIComponent component = columns.next();
             result = (component.isRendered() && (null != component.getValueExpression(attributeName)));
         }
         return result;
     }
 
     @Override
     public RowHolderBase createRowHolder(FacesContext context, UIComponent componentObject[] options) {
         RowHolder rowHolder = null;
         if (component instanceof UIDataTableBase) {
             rowHolder = new RowHolder(context, (UIDataTableBasecomponent);
             rowHolder.setUpdatePartial((Booleanoptions[0]);
             rowHolder.setEncodeParentTBody((Booleanoptions[1]);
         }
 
         return rowHolder;
     }
 
     protected class SimpleHeaderEncodeStrategy implements EncodeStrategy {
         public void begin(ResponseWriter writer, FacesContext context, UIComponent columnObject[] paramsthrows IOException {
         }
 
         public void end(ResponseWriter writer, FacesContext context, UIComponent columnObject[] paramsthrows IOException {
         }
     }
 
     protected void doDecode(FacesContext context, UIComponent component) {
         decodeSortingFiltering(contextcomponent);
     }
 
     protected void putRowStylesIntoContext(FacesContext facesContextRowHolderBase rowHolder) {
         UIDataTableBase dataTableBase = (UIDataTableBaserowHolder.getRow();
 
         String rowClass = getRowSkinClass();
         String cellClass = getCellSkinClass();
         String firstClass = getFirstRowSkinClass();
 
         rowClass = mergeStyleClasses(rowClassdataTableBase);
         cellClass = mergeStyleClasses(cellClassdataTableBase);
         firstClass = mergeStyleClasses(firstClassdataTableBase);
 
         saveRowStyles(facesContextdataTableBase.getClientId(facesContext), firstClassrowClasscellClass);
     }
 
     protected boolean isEncodeHeaders(UIDataTableBase table) {
         return table.isColumnFacetPresent(.) || isColumnAttributeSet(table"sortBy")
             || isColumnAttributeSet(table"comparator") || isColumnAttributeSet(table"filterBy");
     }
 
    public void encodeTableStructure(ResponseWriter writer, FacesContext contextUIDataTableBase dataTablethrows IOException {
        // DataTableRenderer override this method
    }
    public void encodeBeforeRows(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase,
        boolean encodeParentTBodyboolean partialUpdatethrows IOException {
    }
    public void encodeAfterRows(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase,
        boolean encodeParentTBodyboolean partialUpdatethrows IOException {
    }
    public abstract boolean encodeParentTBody(UIDataTableBase dataTableBase);
    public void encodeTableFacets(ResponseWriter writer, FacesContext contextUIDataTableBase dataTablethrows IOException {
        Object key = dataTable.getRowKey();
        dataTable.captureOrigValue(context);
        dataTable.setRowKey(contextnull);
        encodeTableStructure(writercontextdataTable);
        encodeHeaderFacet(writercontextdataTablefalse);
        encodeFooterFacet(writercontextdataTablefalse);
        dataTable.setRowKey(contextkey);
        dataTable.restoreOrigValue(context);
    }
    public void encodeTableRows(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase,
        boolean encodePartialUpdatethrows IOException {
        int rowCount = dataTableBase.getRowCount();
        Object key = dataTableBase.getRowKey();
        dataTableBase.captureOrigValue(facesContext);
        dataTableBase.setRowKey(facesContextnull);
        boolean encodeParentTBody = encodeParentTBody(dataTableBase);
        encodeBeforeRows(writerfacesContextdataTableBaseencodeParentTBodyencodePartialUpdate);
        if (rowCount > 0) {
            processRows(writerfacesContextdataTableBasenew Object[] { encodePartialUpdateencodeParentTBody });
        } else {
            encodeNoDataFacetOrLabel(writerfacesContextdataTableBase);
        }
        encodeAfterRows(writerfacesContextdataTableBaseencodeParentTBodyencodePartialUpdate);
        if (encodePartialUpdate) {
            String id = dataTableBase.getClientId(facesContext) + ;
            partialStart(facesContextid);
        }
        encodeHiddens(writerfacesContextdataTableBasenew Object[] { encodeParentTBody });
        if (encodePartialUpdate) {
            partialEnd(facesContext);
        }
        dataTableBase.setRowKey(facesContextkey);
        dataTableBase.restoreOrigValue(facesContext);
    }
    public void encodeNoDataFacetOrLabel(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase)
        throws IOException {
        int columns = getColumnsCount(dataTableBase.columns());
        UIComponent noDataFacet = dataTableBase.getNoData();
        String noDataLabel = dataTableBase.getNoDataLabel();
        writer.startElement(HtmlConstants.TR_ELEMENT, dataTableBase);
        String styleClass = (StringdataTableBase.getAttributes().get("noDataStyleClass");
        styleClass = concatClasses(getNoDataClass(), styleClass);
        writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, styleClassnull);
        writer.startElement(HtmlConstants.TD_ELEM, dataTableBase);
        writer.writeAttribute(HtmlConstants.COLSPAN_ATTRIBUTE, columnsnull);
        String cellStyleClass = (StringdataTableBase.getAttributes().get("noDataCellStyleClass");
        cellStyleClass = concatClasses(getNoDataCellClass(), cellStyleClass);
        writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, cellStyleClassnull);
        if (noDataFacet != null && noDataFacet.isRendered()) {
            noDataFacet.encodeAll(facesContext);
        } else if (noDataLabel != null && noDataLabel.length() > 0) {
            writer.writeText(noDataLabel"noDataLabel");
        } else {
            writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, "display: none;"null);
        }
        writer.endElement(HtmlConstants.TD_ELEM);
        writer.endElement(HtmlConstants.TR_ELEMENT);
    }

    
Clear the extendedDataModel before the component encode begins. This is to force the extendedDataModel to be re-initialized taking into account any model changes that were applied since the model was created in the RESTORE_VIEW phase.

Parameters:
context
component
Throws:
IOException
    @Override
    protected void preEncodeBegin(FacesContext context, UIComponent componentthrows IOException {
        super.preEncodeBegin(contextcomponent);
        if (component instanceof UIDataTableBase) {
            ((UIDataTableBasecomponent).clearExtendedDataModel();
        }
    }
    protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        if (component instanceof UIDataTableBase) {
            encodeTableRows(writercontext, (UIDataTableBasecomponentfalse);
        }
    }
    public void encodeTableStart(ResponseWriter writer, FacesContext contextUIDataTableBase componentthrows IOException {
        writer.startElement(HtmlConstants.TABLE_ELEMENT, component);
        writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, component.getClientId(context), null);
        String styleClass = getTableSkinClass();
        encodeStyleClass(writercontextcomponent, HtmlConstants.STYLE_CLASS_ATTR, styleClass);
    }
    protected void encodeHiddens(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase,
        Object[] paramsthrows IOException {
        EncodeStrategy encodeStrategy = getHiddenContainerStrategy(dataTableBase);
        if (encodeStrategy != null) {
            encodeStrategy.begin(writerfacesContextdataTableBaseparams);
            encodeClientScript(writerfacesContextdataTableBase);
            encodeHiddenInput(writerfacesContextdataTableBase);
            encodeStrategy.end(writerfacesContextdataTableBaseparams);
        }
    }
    public void encodeTableEnd(ResponseWriter writerthrows IOException {
        writer.endElement(HtmlConstants.TABLE_ELEMENT);
    }
    public abstract void encodeClientScript(ResponseWriter writer, FacesContext contextUIDataTableBase component)
        throws IOException;
    public abstract void encodeHiddenInput(ResponseWriter writer, FacesContext contextUIDataTableBase component)
        throws IOException;
    public void encodeTableBodyStart(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTableBase)
        throws IOException {
        writer.startElement(HtmlConstants.TBODY_ELEMENT, dataTableBase);
        String clientId = (dataTableBase.getRowKey() == null) ? dataTableBase.getContainerClientId(facesContext)
            : dataTableBase.getRelativeClientId(facesContext);
        writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, clientId + ":tb"null);
        writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, getTableBodySkinClass(), null);
    }
    public void encodeTableBodyEnd(ResponseWriter writerthrows IOException {
        writer.endElement(HtmlConstants.TBODY_ELEMENT);
    }
    public void encodeFooterFacet(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTable,
        boolean encodePartialUpdatethrows IOException {
        UIComponent footer = dataTable.getFooter();
        boolean columnFacetPresent = dataTable.isColumnFacetPresent("footer");
        if ((footer != null && footer.isRendered()) || columnFacetPresent) {
            boolean partialUpdateEncoded = false;
            String clientId = dataTable.getClientId(facesContext);
            boolean encodeTfoot = containsThead();
            if (encodeTfoot) {
                String footerClientId = clientId + ":tf";
                if (encodePartialUpdate) {
                    partialUpdateEncoded = true;
                    partialStart(facesContextfooterClientId);
                }
                writer.startElement(HtmlConstants.TFOOT_ELEMENT, dataTable);
                writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, footerClientIdnull);
                writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-dt-tft"null);
            }
            int columns = getColumnsCount(dataTable.columns());
            boolean encodePartialUpdateForChildren = (encodePartialUpdate && !partialUpdateEncoded);
            if (columnFacetPresent) {
                String rowClass = getColumnFooterSkinClass();
                String cellClass = getColumnFooterCellSkinClass();
                String firstClass = getColumnFooterFirstSkinClass();
                rowClass = mergeStyleClasses("columnFooterClass"rowClassdataTable);
                cellClass = mergeStyleClasses("columnFooterCellClass"cellClassdataTable);
                firstClass = mergeStyleClasses("firstColumnFooterClass"firstClassdataTable);
                saveRowStyles(facesContextclientIdfirstClassrowClasscellClass);
                String targetId = clientId + ":cf";
                if (encodePartialUpdateForChildren) {
                    partialStart(facesContexttargetId);
                }
                writer.startElement(HtmlConstants.TR_ELEMENT, dataTable);
                writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, targetIdnull);
                encodeStyleClass(writerfacesContextdataTablenullrowClass);
                encodeColumnFacet(facesContextwriterdataTable.columnscellClass);
                writer.endElement(HtmlConstants.TR_ELEMENT);
                if (encodePartialUpdateForChildren) {
                    partialEnd(facesContext);
                }
            }
            if (footer != null && footer.isRendered()) {
                String rowClass = getFooterSkinClass();
                String cellClass = getFooterCellSkinClass();
                String firstClass = getFooterFirstSkinClass();
                rowClass = mergeStyleClasses("footerClass"rowClassdataTable);
                cellClass = mergeStyleClasses("footerCellClass"cellClassdataTable);
                firstClass = mergeStyleClasses("footerFirstClass"firstClassdataTable);
                // TODO nick - rename method "encodeTableHeaderFacet"
                saveRowStyles(facesContextclientIdfirstClassrowClasscellClass);
                encodeTableFacet(facesContextwriterclientIdcolumnsfooter.rowClasscellClass,
                    encodePartialUpdateForChildren);
            }
            if (encodeTfoot) {
                writer.endElement(HtmlConstants.TFOOT_ELEMENT);
                if (partialUpdateEncoded) {
                    partialEnd(facesContext);
                }
            }
        }
    }
    protected String mergeStyleClasses(String classAttribibuteString skinClass, UIComponent component) {
        String resultClass = skinClass;
        String styleClass = null;
        if (classAttribibute != null && component != null) {
            styleClass = (Stringcomponent.getAttributes().get(classAttribibute);
        }
        return HtmlUtil.concatClasses(resultClassstyleClass);
    }
    public void encodeHeaderFacet(ResponseWriter writer, FacesContext facesContextUIDataTableBase dataTable,
        boolean encodePartialUpdatethrows IOException {
        UIComponent header = dataTable.getHeader();
        boolean isEncodeHeaders = isEncodeHeaders(dataTable);
        boolean encodeThead = containsThead();
        if ((header != null && header.isRendered()) || isEncodeHeaders) {
            String id = dataTable.getClientId(facesContext);
            boolean partialUpdateEncoded = false;
            String clientId = dataTable.getClientId(facesContext);
            if (encodeThead) {
                String headerClientId = clientId + ":th";
                if (encodePartialUpdate) {
                    partialUpdateEncoded = true;
                    partialStart(facesContextheaderClientId);
                }
                writer.startElement(HtmlConstants.THEAD_ELEMENT, dataTable);
                setCellElement(facesContextid, HtmlConstants.TH_ELEM);
                writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, headerClientIdnull);
                writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-dt-thd"null);
            }
            int columns = getColumnsCount(dataTable.columns());
            boolean encodePartialUpdateForChildren = (encodePartialUpdate && !partialUpdateEncoded);
            if (header != null && header.isRendered()) {
                String rowClass = getHeaderSkinClass();
                String cellClass = getHeaderCellSkinClass();
                String firstClass = getHeaderFirstSkinClass();
                rowClass = mergeStyleClasses("headerClass"rowClassdataTable);
                cellClass = mergeStyleClasses("headerCellClass"cellClassdataTable);
                firstClass = mergeStyleClasses("headerFirstClass"firstClassdataTable);
                saveRowStyles(facesContextclientIdfirstClassrowClasscellClass);
                encodeTableFacet(facesContextwriterclientIdcolumnsheader.rowClasscellClass,
                    encodePartialUpdateForChildren);
            }
            if (isEncodeHeaders) {
                String rowClass = getColumnHeaderSkinClass();
                String cellClass = getColumnHeaderCellSkinClass();
                String firstClass = getColumnHeaderFirstSkinClass();
                rowClass = mergeStyleClasses("columnHeaderClass"rowClassdataTable);
                cellClass = mergeStyleClasses("columnHeaderCellClass"cellClassdataTable);
                firstClass = mergeStyleClasses("columnHeaderFirstClass"firstClassdataTable);
                saveRowStyles(facesContextclientIdfirstClassrowClasscellClass);
                String targetId = clientId + ":ch";
                if (encodePartialUpdateForChildren) {
                    partialStart(facesContexttargetId);
                }
                writer.startElement(HtmlConstants.TR_ELEMENT, dataTable);
                writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, targetIdnull);
                encodeStyleClass(writerfacesContextdataTablenullrowClass);
                encodeColumnFacet(facesContextwriterdataTable.columnscellClass);
                writer.endElement(HtmlConstants.TR_ELEMENT);
                if (encodePartialUpdateForChildren) {
                    partialEnd(facesContext);
                }
            }
            if (encodeThead) {
                setCellElement(facesContextidnull);
                writer.endElement(HtmlConstants.THEAD_ELEMENT);
                if (partialUpdateEncoded) {
                    partialEnd(facesContext);
                }
            }
        }
    }
    protected void encodeColumnFacet(FacesContext context, ResponseWriter writerUIDataTableBase dataTableBase,
        String facetNameint colCountString cellClassthrows IOException {
        int tColCount = 0;
        String id = dataTableBase.getClientId(context);
        String element = getCellElement(contextid);
        Iterator<UIComponent> headers = dataTableBase.columns();
        while (headers.hasNext()) {
            UIComponent column = headers.next();
            if (!column.isRendered() || (column instanceof Row)) {
                continue;
            }
            Integer colspan = (Integercolumn.getAttributes().get(HtmlConstants.COLSPAN_ATTRIBUTE);
            if (colspan != null && colspan.intValue() > 0) {
                tColCount += colspan.intValue();
            } else {
                tColCount++;
            }
            if (tColCount > colCount) {
                break;
            }
            writer.startElement(elementcolumn);
            encodeStyleClass(writercontextcolumnfacetName + "Class"cellClass);
            if (HtmlConstants.TH_ELEM.equals(element)) { // HTML5 allows scope attr only on th elements
                writer.writeAttribute(HtmlConstants.SCOPE_ATTRIBUTE, HtmlConstants.COL_ELEMENT, null);
            }
            getUtils().encodeAttribute(contextcolumn, HtmlConstants.COLSPAN_ATTRIBUTE);
            EncodeStrategy strategy = getHeaderEncodeStrategy(columnfacetName);
            if (strategy != null) {
                strategy.begin(writercontextcolumnnew String[] { facetName });
                UIComponent facet = column.getFacet(facetName);
                if (facet != null && facet.isRendered()) {
                    facet.encodeAll(context);
                }
                strategy.end(writercontextcolumnnew String[] { facetName });
            }
            writer.endElement(element);
        }
    }
    protected void encodeTableFacet(FacesContext facesContext, ResponseWriter writerString idint columns,
        UIComponent footerString facetNameString rowClassString cellClassboolean encodePartialUpdate)
        throws IOException {
        boolean isColumnGroup = (footer instanceof Row);
        String element = getCellElement(facesContextid);
        boolean partialUpdateEncoded = false;
        if (!isColumnGroup) {
            String targetId = id + ":" + facetName.charAt(0);
            if (encodePartialUpdate) {
                partialUpdateEncoded = true;
                partialStart(facesContexttargetId);
            }
            writer.startElement(HtmlConstants.TR_ELEMENT, footer);
            writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, targetIdnull);
            encodeStyleClass(writerfacesContextfooternullrowClass);
            writer.startElement(elementfooter);
            encodeStyleClass(writerfacesContextfooternullcellClass);
            if (columns > 0) {
                writer.writeAttribute(HtmlConstants.COLSPAN_ATTRIBUTE, String.valueOf(columns), null);
            }
            if (HtmlConstants.TH_ELEM.equals(element)) { // HTML5 allows scope attr only on th elements
                writer.writeAttribute(HtmlConstants.SCOPE_ATTRIBUTE, HtmlConstants.COLGROUP_ELEMENT, null);
            }
        }
        if (encodePartialUpdate && !partialUpdateEncoded) {
            partialStart(facesContextfooter.getClientId(facesContext));
        }
        footer.encodeAll(facesContext);
        if (encodePartialUpdate && !partialUpdateEncoded) {
            partialEnd(facesContext);
        }
        if (isColumnGroup) {
            writer.endElement(HtmlConstants.TR_ELEMENT);
        } else {
            writer.endElement(element);
            writer.endElement(HtmlConstants.TR_ELEMENT);
            if (partialUpdateEncoded) {
                partialEnd(facesContext);
            }
        }
    }
    public abstract EncodeStrategy getHeaderEncodeStrategy(UIComponent columnString tableFacetName);
    public abstract boolean containsThead();
    public abstract String getTableSkinClass();
    public abstract String getTableBodySkinClass();
    public abstract String getFirstRowSkinClass();
    public abstract String getRowSkinClass();
    public abstract String getHeaderCellSkinClass();
    public abstract String getHeaderSkinClass();
    public abstract String getHeaderFirstSkinClass();
    public abstract String getColumnHeaderCellSkinClass();
    public abstract String getColumnHeaderSkinClass();
    public abstract String getColumnHeaderFirstSkinClass();
    public abstract String getFooterCellSkinClass();
    public abstract String getFooterSkinClass();
    public abstract String getFooterFirstSkinClass();
    public abstract String getColumnFooterCellSkinClass();
    public abstract String getColumnFooterSkinClass();
    public abstract String getColumnFooterFirstSkinClass();
    public abstract String getCellSkinClass();
    public abstract String getNoDataClass();
    public abstract String getNoDataCellClass();
    public void encodeMetaComponent(FacesContext context, UIComponent componentString metaComponentIdthrows IOException {
        UIDataTableBase table = (UIDataTableBasecomponent;
        if (..equals(metaComponentId)) {
            encodeHeaderFacet(context.getResponseWriter(), contexttabletrue);
        } else if (..equals(metaComponentId)) {
            encodeFooterFacet(context.getResponseWriter(), contexttabletrue);
        } else if (..equals(metaComponentId)) {
            encodeTableRows(context.getResponseWriter(), contexttabletrue);
        } else {
            throw new IllegalArgumentException("Unsupported metaComponentIdentifier: " + metaComponentId);
        }
    }
    public void decodeMetaComponent(FacesContext context, UIComponent componentString metaComponentId) {
        throw new UnsupportedOperationException();
    }
    protected void partialStart(FacesContext facesContextString idthrows IOException {
        facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(id);
    }
    protected void partialEnd(FacesContext facesContextthrows IOException {
        facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
    }
New to GrepCode? Check out our FAQ X