public <T extends UIComponent> void encodeCells(final Element<T> tbody, Iterator<UIDataCell> cellIterator, final int columns) throws IOException {
int column = 0;
Element<T> tr = null;
while (cellIterator.hasNext()) {
final UIDataCell dataCell = cellIterator.next();
if (column == 0) {
tr = tbody.writeElement("tr");
}
final UIComponent headerFacet = dataCell.getFacet("header");
if (headerFacet != null) {
Element<UIComponent> th = tr.writeElement("th", headerFacet);
th.writeAttribute("scope", "colgroup");
th.addClass(dataCell.getHeaderClass()).writeClass();
th.addStyle(dataCell.getHeaderStyle()).writeStyle();
th.doEncode();
th.close();
} else {
tr.writeElement("th").close();
}
final Element<UIDataCell> td = tr.writeElement("td", dataCell);
td.writeId();
td.addClass(dataCell.getStyleClass()).writeClass();
td.addStyle(dataCell.getStyle()).writeStyle();
td.doEncode();
td.close();
column = (column + 1) % columns;
if (column == 0) {