public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
if (! component.isRendered()) {
return;
}
UIDataForm dataForm = ((UIDataForm)component);
final int columns = dataForm.getColumns();
final int colspan = columns * 2;
final Element<UIDataForm> table = writeElement(context, "table", dataForm);
table.writeId();
table.addClass(dataForm.getStyleClass()).writeClass();
table.addStyle(dataForm.getStyle()).writeStyle();
for (int i = 0; i < columns; i ++) {
final Element<UIDataForm> colgroup = table.writeElement("colgroup");
colgroup.writeAttribute("span", 2);
colgroup.close();
}
final UIComponent dataFormHeader = dataForm.getFacet("header");
final UIComponent dataFormFooter = dataForm.getFacet("footer");
if (dataFormHeader != null) {
final Element<UIComponent> thead = table.writeElement("thead", dataFormHeader);
thead.addClass(dataForm.getHeaderClass()).writeClass();
thead.addStyle(dataForm.getHeaderStyle()).writeClass();
final Element<UIComponent> tr = thead.writeElement("tr");
final Element<UIComponent> th = tr.writeElement("th");
th.writeAttribute("colspan", colspan);
th.doEncode();
th.close();
tr.close();
thead.close();
}
if (dataFormFooter != null) {
final Element<UIComponent> tfoot = table.writeElement("tfoot", dataFormFooter);
tfoot.addClass(dataForm.getFooterClass()).writeClass();
tfoot.addStyle(dataForm.getFooterStyle()).writeClass();
final Element<UIComponent> tr = tfoot.writeElement("tr");
final Element<UIComponent> th = tr.writeElement("th");
th.writeAttribute("colspan", colspan);
th.doEncode();
th.close();
tr.close();
tfoot.close();
}
final Iterator<UIDataSection> sectionIter = dataForm.getChildrenOfType(UIDataSection.class);
boolean sections = false;
while (sectionIter.hasNext()) {
sections = true;
final UIDataSection section = sectionIter.next();
final Element<UIDataSection> tbody = table.writeElement("tbody", section);
final UIComponent sectionHeader = section.getFacet("header");
final UIComponent sectionFooter = section.getFacet("footer");
if (sectionHeader != null) {
final Element<UIComponent> tr = tbody.writeElement("tr", sectionHeader);
final Element<UIComponent> th = tr.writeElement("th");
th.writeAttribute("scope", "rowgroup");
th.writeAttribute("colspan", colspan);
th.doEncode();
th.close();
tr.close();
}
if (section instanceof UIDataArea) {
final Element<UIDataSection> tr = tbody.writeElement("tr");
final Element<UIDataSection> td = tr.writeElement("td");
td.writeAttribute("colspan", colspan);
td.doEncode();
td.close();
tr.close();
} else {
encodeCells(tbody, section.getChildrenOfType(UIDataCell.class), columns);
}
if (sectionFooter != null) {
final Element<UIComponent> tr = tbody.writeElement("tr", sectionFooter);
final Element<UIComponent> th = tr.writeElement("th");
th.writeAttribute("colspan", colspan);
th.doEncode();
th.close();
tr.close();
}
tbody.close();
}
if (! sections) {
final Element<UIDataForm> tbody = table.writeElement("tbody");
encodeCells(tbody, dataForm.getChildrenOfType(UIDataCell.class), columns);
tbody.close();
}
table.close();
}