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 jakarta.faces Show documentation
Show all versions of jakarta.faces Show documentation
EE4J Compatible Implementation for Jakarta Faces API
The newest version!
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.faces.renderkit.html_basic;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.sun.faces.renderkit.Attribute;
import com.sun.faces.renderkit.RenderKitUtils;
import com.sun.faces.util.Util;
import jakarta.faces.component.UIColumn;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIData;
import jakarta.faces.context.FacesContext;
import jakarta.faces.context.ResponseWriter;
/**
* 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);
final String tableRowClass = info.rowClasses.length > 0 ? info.getCurrentRowClass() : null;
final String rowClass = (String) table.getAttributes().get("rowClass");
if (tableRowClass != null) {
if (rowClass != null) {
throw new IOException("Cannot define both rowClasses on a table and rowClass");
}
writer.writeAttribute("class", tableRowClass, "rowClasses");
}
if (rowClass != null) {
if (tableRowClass != null) {
throw new IOException("Cannot define both rowClasses on a table and rowClass");
}
writer.writeAttribute("class", rowClass, "rowClass");
}
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