dev@javaserverfaces.java.net

[PATCH] Add class attribute to <tr> tags in dataTable

From: David M. Lloyd <david.lloyd_at_jboss.com>
Date: Wed, 11 Oct 2006 09:45:09 -0500

Please consider the following patch (against the jsf1.2_02fcs-src
zipfile). It adds headerClass/footerClass to <tr> elements associated
with the header and footer in a dataTable, which (I think) makes some
CSS stuff possible that otherwise isn't.

I wonder if it would be useful to put the class attribute on the
<thead>, <tbody>, and <tfoot> elements too (it probably couldn't hurt).

I'm not subscribed, so please CC me on all replies.

Thanks!

- DML

diff -r -U30 src-old/com/sun/faces/renderkit/html_basic/TableRenderer.java src/com/sun/faces/renderkit/html_basic/TableRenderer.java
--- src-old/com/sun/faces/renderkit/html_basic/TableRenderer.java 2006-05-18 18:07:55.000000000 -0500
+++ src/com/sun/faces/renderkit/html_basic/TableRenderer.java 2006-10-11 09:37:25.000000000 -0500
@@ -97,124 +97,136 @@
                                                 component,
                                                 new String[] {"rows"});
         writer.writeText("\n", component, null);
         
         UIComponent caption = getFacet(data, "caption");
         if (caption != null) {
             String captionClass = (String) data.getAttributes().get("captionClass");
             String captionStyle = (String)
                 data.getAttributes().get("captionStyle");
             writer.startElement("caption", data);
             if (captionClass != null) {
                 writer.writeAttribute("class", captionClass, "captionClass");
             }
             if (captionStyle != null) {
                 writer.writeAttribute("style", captionStyle, "captionStyle");
             }
             encodeRecursive(context, caption);
             writer.endElement("caption");
         }
 
         // Render the header facets (if any)
         UIComponent header = getFacet(data, "header");
         int headerFacets = getFacetCount(data, "header");
         String headerClass = (String) data.getAttributes().get("headerClass");
         if ((header != null) || (headerFacets > 0)) {
             writer.startElement("thead", data);
             writer.writeText("\n", component, null);
         }
         if (header != null) {
             writer.startElement("tr", header);
+ if (headerClass != null) {
+ writer.writeAttribute("class", headerClass, "headerClass");
+ }
             writer.startElement("th", header);
             if (headerClass != null) {
                 writer.writeAttribute("class", headerClass, "headerClass");
             }
             writer.writeAttribute("colspan", "" + getColumnCount(data), null);
             writer.writeAttribute("scope", "colgroup", null);
             encodeRecursive(context, header);
             writer.endElement("th");
             writer.endElement("tr");
             writer.writeText("\n", component, null);
         }
         if (headerFacets > 0) {
             writer.startElement("tr", data);
+ if (headerClass != null) {
+ writer.writeAttribute("class", headerClass, "headerClass");
+ }
             writer.writeText("\n", component, null);
             Iterator<UIColumn> columns = getColumns(data);
             while (columns.hasNext()) {
                 UIColumn column = columns.next();
                 String columnHeaderClass =
                     (String) column.getAttributes().get("headerClass");
                 writer.startElement("th", column);
                 if (columnHeaderClass != null) {
                     writer.writeAttribute("class", columnHeaderClass,
                         "columnHeaderClass");
                 } else if (headerClass != null) {
                     writer.writeAttribute("class", headerClass, "headerClass");
                 }
                 writer.writeAttribute("scope", "col", null);
                 UIComponent facet = getFacet(column, "header");
                 if (facet != null) {
                     encodeRecursive(context, facet);
                 }
                 writer.endElement("th");
                 writer.writeText("\n", component, null);
             }
             writer.endElement("tr");
             writer.writeText("\n", component, null);
         }
         if ((header != null) || (headerFacets > 0)) {
             writer.endElement("thead");
             writer.writeText("\n", component, null);
         }
 
         // Render the footer facets (if any)
         UIComponent footer = getFacet(data, "footer");
         int footerFacets = getFacetCount(data, "footer");
         String footerClass = (String) data.getAttributes().get("footerClass");
         if ((footer != null) || (footerFacets > 0)) {
             writer.startElement("tfoot", data);
             writer.writeText("\n", component, null);
         }
         if (footer != null) {
             writer.startElement("tr", footer);
+ if (footerClass != null) {
+ writer.writeAttribute("class", footerClass, "footerClass");
+ }
             writer.startElement("td", footer);
             if (footerClass != null) {
                 writer.writeAttribute("class", footerClass, "footerClass");
             }
             writer.writeAttribute("colspan", "" + getColumnCount(data), null);
             encodeRecursive(context, footer);
             writer.endElement("td");
             writer.endElement("tr");
             writer.writeText("\n", component, null);
         }
         if (footerFacets > 0) {
             writer.startElement("tr", data);
+ if (footerClass != null) {
+ writer.writeAttribute("class", footerClass, "footerClass");
+ }
             writer.writeText("\n", component, null);
             Iterator<UIColumn> columns = getColumns(data);
             while (columns.hasNext()) {
                 UIColumn column = columns.next();
                 String columnFooterClass =
                     (String) column.getAttributes().get("footerClass");
                 writer.startElement("td", column);
                 if (columnFooterClass != null) {
                     writer.writeAttribute("class", columnFooterClass,
                         "columnFooterClass");
                 } else if (footerClass != null) {
                     writer.writeAttribute("class", footerClass, "footerClass");
                 }
                 UIComponent facet = getFacet(column, "footer");
                 if (facet != null) {
                     encodeRecursive(context, facet);
                 }
                 writer.endElement("td");
                 writer.writeText("\n", component, null);
             }
             writer.endElement("tr");
             writer.writeText("\n", component, null);
         }
         if ((footer != null) || (footerFacets > 0)) {
             writer.endElement("tfoot");
             writer.writeText("\n", component, null);
         }
 
     }