com.sun.faces.renderkit.html_basic.BaseTableRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javax.faces Show documentation
Show all versions of javax.faces Show documentation
This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.renderkit.html_basic;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.component.UIComponent;
import javax.faces.component.UIColumn;
import javax.faces.component.UIData;
import com.sun.faces.renderkit.Attribute;
import com.sun.faces.renderkit.RenderKitUtils;
import com.sun.faces.util.Util;
/**
* Base class for concrete Grid and Table renderers.
*/
public abstract class BaseTableRenderer extends HtmlBasicRenderer {
// ------------------------------------------------------- Protected Methods
/**
* Called to render the opening/closing thead
elements
* and any content nested between.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
protected abstract void renderHeader(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException;
/**
* Called to render the opening/closing tfoot
elements
* and any content nested between.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
protected abstract void renderFooter(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException;
/**
* Call to render the content that should be included between opening
* and closing tr
elements.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param row the current row (if any - an implmenetation may not need this)
* @param writer the current writer
* @throws IOException if content cannot be written
*/
protected abstract void renderRow(FacesContext context,
UIComponent table,
UIComponent row,
ResponseWriter writer)
throws IOException;
/**
* Renders the start of a table and applies the value of
* styleClass
if available and renders any
* pass through attributes that may be specified.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @param attributes pass-through attributes that the component
* supports
* @throws IOException if content cannot be written
*/
protected void renderTableStart(FacesContext context,
UIComponent table,
ResponseWriter writer,
Attribute[] attributes)
throws IOException {
writer.startElement("table", table);
writeIdAttributeIfNecessary(context, writer, table);
String styleClass = (String) table.getAttributes().get("styleClass");
if (styleClass != null) {
writer.writeAttribute("class", styleClass, "styleClass");
}
RenderKitUtils.renderPassThruAttributes(context,
writer,
table,
attributes);
writer.writeText("\n", table, null);
}
/**
* Renders the closing table
element.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void renderTableEnd(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException {
writer.endElement("table");
writer.writeText("\n", table, null);
}
/**
* Renders the caption of the table applying the values of
* captionClass
as the class and captionStyle
* as the style if either are present.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
protected void renderCaption(FacesContext context,
UIComponent table,
ResponseWriter writer) throws IOException {
UIComponent caption = getFacet(table, "caption");
if (caption != null) {
String captionClass =
(String) table.getAttributes().get("captionClass");
String captionStyle = (String)
table.getAttributes().get("captionStyle");
writer.startElement("caption", table);
if (captionClass != null) {
writer.writeAttribute("class", captionClass, "captionClass");
}
if (captionStyle != null) {
writer.writeAttribute("style", captionStyle, "captionStyle");
}
encodeRecursive(context, caption);
writer.endElement("caption");
}
}
/**
* Renders the starting tbody
element.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void renderTableBodyStart(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException {
writer.startElement("tbody", table);
writer.writeText("\n", table, null);
}
/**
* Renders the closing tbody
element.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void renderTableBodyEnd(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException {
writer.endElement("tbody");
writer.writeText("\n", table, null);
}
/**
* Renders the starting tr
element applying any values
* from the rowClasses
attribute.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
protected void renderRowStart(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException {
TableMetaInfo info = getMetaInfo(context, table);
writer.startElement("tr", table);
if (info.rowClasses.length > 0) {
writer.writeAttribute("class", info.getCurrentRowClass(),
"rowClasses");
}
writer.writeText("\n", table, null);
}
/**
* Renders the closing rt
element.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @param writer the current writer
* @throws IOException if content cannot be written
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void renderRowEnd(FacesContext context,
UIComponent table,
ResponseWriter writer)
throws IOException {
writer.endElement("tr");
writer.writeText("\n", table, null);
}
/**
* Returns a TableMetaInfo
object containing details such
* as row and column classes, columns, and a mechanism for scrolling through
* the row/column classes.
* @param context the FacesContext
for the current request
* @param table the table that's being rendered
* @return the TableMetaInfo
for provided table
*/
protected TableRenderer.TableMetaInfo getMetaInfo(FacesContext context,
UIComponent table) {
String key = createKey(table);
Map