Author: akushunin
Date: 2007-04-26 12:08:06 -0400 (Thu, 26 Apr 2007)
New Revision: 577
Modified:
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/html/SubTableRenderer.java
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
Log:
fixed problems with dataTable...
Modified:
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2007-04-26
16:03:46 UTC (rev 576)
+++
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2007-04-26
16:08:06 UTC (rev 577)
@@ -34,7 +34,6 @@
import org.apache.commons.collections.iterators.FilterIterator;
import org.richfaces.component.Column;
import org.richfaces.component.Row;
-import org.richfaces.component.UIColumnGroup;
import org.richfaces.component.UIDataTable;
/**
@@ -78,8 +77,10 @@
int columns) throws IOException {
ResponseWriter writer = context.getResponseWriter();
UIComponent header = table.getHeader();
- Iterator headers = columnFacets(table);
- if (header != null || headers.hasNext()) {
+ Iterator headers = columnFacets(table,"header");
+
+
+ if (header != null ||headers.hasNext()) {
writer.startElement("thead", table);
String headerClass = (String) table.getAttributes().get(
"headerClass");
@@ -91,20 +92,37 @@
headerClass, "td");
}
- if (headers.hasNext()) {
+ if (headers.hasNext()&&findFacet(table,"header")) {
writer.startElement("tr", table);
encodeStyleClass(writer, null,
"dr-table-subheader rich-table-subheader", null,
headerClass);
- encodeHeaderFacets(context, writer, headers,
+ encodeHeaderFacets(context, writer, headers,
"dr-table-subheadercell rich-table-subheadercell",
headerClass, "header", "td");
+
writer.endElement("tr");
}
writer.endElement("thead");
}
}
-
+
+ public boolean findFacet(UIDataTable table, String facetName)
+ {
+ Iterator iter = columnFacets(table,facetName);
+ boolean find = false;
+ while(iter.hasNext()){
+ UIComponent comp = (UIComponent) iter.next();
+ if(comp.getFacet(facetName)!=null)
+ {
+ find = true;
+ break;
+ }
+
+ }
+ return find;
+ }
+
protected void encodeHeaderFacets(FacesContext context,
ResponseWriter writer, Iterator headers, String skinCellClass,
String headerClass, String facetName, String element)
@@ -114,15 +132,17 @@
String classAttribute = facetName + "Class";
String columnHeaderClass = (String) column.getAttributes().get(
classAttribute);
+
writer.startElement(element, column);
encodeStyleClass(writer, null, skinCellClass, headerClass,
columnHeaderClass);
writer.writeAttribute("scope", "col", null);
getUtils().encodeAttribute(context, column, "colspan");
UIComponent facet = column.getFacet(facetName);
- if (facet != null && facet.isRendered()) {
+ if (facet != null) {
renderChild(context, facet);
}
+
writer.endElement(element);
}
}
@@ -131,20 +151,22 @@
int columns) throws IOException {
ResponseWriter writer = context.getResponseWriter();
UIComponent footer = table.getFooter();
- Iterator footers = columnFacets(table);
+ Iterator footers = columnFacets(table,"footer");
if (footer != null || footers.hasNext()) {
writer.startElement("tfoot", table);
String footerClass = (String) table.getAttributes().get(
"footerClass");
- if (footers.hasNext()) {
+ if (footers.hasNext()&&findFacet(table,"footer")) {
writer.startElement("tr", table);
encodeStyleClass(writer, null,
"dr-table-subfooter rich-table-subfooter", null,
footerClass);
+
encodeHeaderFacets(context, writer, footers,
"dr-table-subfootercell rich-table-subfootercell",
footerClass, "footer", "td");
+
writer.endElement("tr");
}
if (footer != null) {
@@ -264,18 +286,18 @@
*
* Changed by Alexej Kushunin
*/
- protected Iterator columnFacets(UIDataTable table){
+ protected Iterator columnFacets(UIDataTable table,final String name){
return new FilterIterator(table.columns(), new Predicate() {
public boolean evaluate(Object input) {
UIComponent component = (UIComponent) input;
- // accept only components which work with facets.
- if (component instanceof UIColumnGroup) {
- return false;
+ // accept only columns with corresponding facets.
+ if (component instanceof Column) {
+ return component.isRendered()&&(component.getFacet(name) != null);
}
else{
- return component.isRendered();}
- // && component.getFacet(name) != null;
+ return false;
+ }
}});
}
Modified:
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/html/SubTableRenderer.java
===================================================================
---
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/html/SubTableRenderer.java 2007-04-26
16:03:46 UTC (rev 576)
+++
trunk/richfaces/dataTable/src/main/java/org/richfaces/renderkit/html/SubTableRenderer.java 2007-04-26
16:08:06 UTC (rev 577)
@@ -59,13 +59,14 @@
*/
private void encodeHeaderRow(ResponseWriter writer, FacesContext context, UIComponent
component,String facetName) throws IOException {
UIDataTable dataTable = (UIDataTable) component;
- Iterator headers = columnFacets(dataTable);
+ Iterator headers = columnFacets(dataTable,facetName);
String headerClass = (String) component.getAttributes().get(
facetName+"Class");
- if (headers.hasNext()) {
+ if (headers.hasNext()&&findFacet(dataTable,facetName)) {
encodeRowStart(context,"dr-subtable-"+facetName+"
rich-subtable-"+facetName ,headerClass, dataTable, writer);
encodeHeaderFacets(context, writer, headers,
"dr-subtable-"+facetName+"cell
rich-subtable-"+facetName+"cell", headerClass,
facetName, "td");
+
writer.endElement("tr");
}
}
Modified:
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
===================================================================
---
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java 2007-04-26
16:03:46 UTC (rev 576)
+++
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java 2007-04-26
16:08:06 UTC (rev 577)
@@ -324,16 +324,16 @@
tr = (HtmlElement) trs.get(0);
assertNotNull(tr);
classAttr = tr.getAttributeValue("class");
-// System.out.println(classAttr);
- assertTrue(classAttr.contains("dr-table-subfooter rich-table-subfooter
"));
+ System.out.println(classAttr);
+ assertTrue(classAttr.contains("dr-table-footer rich-table-footer "));
tds = tr.getHtmlElementsByTagName("td");
assertTrue(tds.size() > 0);
td = (HtmlElement) tds.get(0);
assertNotNull(td);
classAttr = td.getAttributeValue("class");
-// System.out.println(classAttr);
- assertTrue(classAttr.contains("dr-table-subfootercell
rich-table-subfootercell "));
+ System.out.println(classAttr);
+ assertTrue(classAttr.contains("dr-table-footercell rich-table-footercell
"));
Iterator fixedChildren = dataTable.fixedChildren();
assertNotNull(fixedChildren);