public void encodeChildrenOfComponent(FacesContext facesContext, UIComponent component)
throws IOException {
// encode table with component's children
UIGridLayout layout = (UIGridLayout) UILayout.getLayout(component);
HtmlRendererUtil.prepareRender(facesContext, layout);
layoutEnd(facesContext, layout);
layoutMargins(layout);
final Map attributes = layout.getAttributes();
List columnWidths = (List) attributes.get(ATTR_WIDTH_LIST);
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlConstants.TABLE, layout);
writer.writeAttributeFromComponent(HtmlAttributes.BORDER, ATTR_BORDER);
writer.writeClassAttribute();
writer.writeStyleAttribute();
writer.writeAttribute(HtmlAttributes.CELLSPACING, 0);
writer.writeAttribute(HtmlAttributes.CELLPADDING, 0);
writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);
boolean first = true;
if (columnWidths != null) {
writer.startElement(HtmlConstants.COLGROUP, null);
for (int i = 0; i < columnWidths.size(); i++) {
int cellWidth = ((Integer) columnWidths.get(i)).intValue();
if (cellWidth != LayoutInfo.HIDE) {
cellWidth += getCellPadding(facesContext, layout, first);
first = false;
writer.startElement(HtmlConstants.COL, null);
writer.writeAttribute(HtmlAttributes.WIDTH, cellWidth);
writer.endElement(HtmlConstants.COL);
}
}
writer.endElement(HtmlConstants.COLGROUP);
}
List<UIGridLayout.Row> rows = layout.ensureRows();
boolean firstRenderedRow = true;
for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
UIGridLayout.Row row = rows.get(rowIndex);
if (!row.isHidden()) {
writer.startElement(HtmlConstants.TR, null);
List cells = row.getElements();
boolean firstRenderedColum = true;
for (int columnIndex = 0; columnIndex < cells.size(); columnIndex++) {
boolean hide = false;
if (columnWidths != null) {
Integer columWidth = ((Integer) columnWidths.get(columnIndex));
hide = columWidth.intValue() == LayoutInfo.HIDE;
}
if (!hide) {
Object object = cells.get(columnIndex);
if (object.toString().equals(UIGridLayout.USED)) {
firstRenderedColum = false;
continue; // ignore the markers UIGridLayout.Used
} else if (object.equals(UIGridLayout.FREE)) {
if (LOG.isWarnEnabled() && !layout.isIgnoreFree()) {
LOG.warn("There are free blocks in the layout: id='"
+ layout.getClientId(facesContext)
+ "'");
}
firstRenderedColum = false;
continue;
}
UIComponent cell = (UIComponent) object;
int spanX = UIGridLayout.getSpanX(cell);
int spanY = UIGridLayout.getSpanY(cell);
StyleClasses classes = StyleClasses.ensureStyleClassesCopy(layout);
if (firstRenderedRow) {
classes.addClass("gridLayout", "first-row"); // XXX not a standard compliant name
}
if (firstRenderedColum) {
classes.addClass("gridLayout", "first-column"); // XXX not a standard compliant name
}
int cellWidth = -1;
if (columnWidths != null) {
cellWidth = 0;
for (int i = columnIndex;
i < columnIndex + spanX && i < columnWidths.size(); i++) {
cellWidth += ((Integer) columnWidths.get(i)).intValue()
+ getCellPadding(facesContext, layout, firstRenderedColum);
if (firstRenderedColum) {
firstRenderedColum = false;
}
}
}
int cellHeight = -1;
try {
Integer layoutHeight = LayoutUtil.getLayoutHeight(cell);
if (layoutHeight != null) {
cellHeight = layoutHeight.intValue();
}
} catch (Exception e) {
// ignore
} // ignore, use 0
int topPadding = getCellPadding(facesContext, layout, firstRenderedRow);
String cellStyle =
(cellWidth != -1 ? "width: " + cellWidth + "px;" : "")
+ (cellHeight != -1 ? " height: " + (cellHeight + topPadding) + "px;" : "");
cellStyle += getOverflow(cell);
writer.startElement(HtmlConstants.TD, null);
writer.writeClassAttribute("tobago-gridLayout-cell-td");
writer.writeAttribute(HtmlAttributes.STYLE, cellStyle, false);
if (spanX > 1) {
writer.writeAttribute(HtmlAttributes.COLSPAN, spanX);
}
if (spanY > 1) {
writer.writeAttribute(HtmlAttributes.ROWSPAN, spanY);
}
writer.flush();
if (ComponentUtil.getAttribute(layout, ATTR_CELLSPACING) != null) {
cellStyle += " padding: " + getCellSpacing(facesContext, layout) + "px;";
}
writer.startElement(HtmlConstants.DIV, null);
writer.writeClassAttribute(classes);
writer.writeAttribute(HtmlAttributes.STYLE, cellStyle, false);
writer.flush();
RenderUtil.encode(facesContext, cell);
writer.endElement(HtmlConstants.DIV);
writer.endElement(HtmlConstants.TD);
firstRenderedColum = false;
HtmlRendererUtil.removeStyleClasses(cell);
}
}
writer.endElement(HtmlConstants.TR);
firstRenderedRow = false;
}
}
writer.endElement(HtmlConstants.TABLE);
if (TobagoConfig.getInstance(facesContext).isFixLayoutTransparency()) {
for (UIComponent child : (List<UIComponent>) layout.getParent().getChildren()) {
if (child instanceof UIHiddenInput) {
RenderUtil.encode(facesContext, child);
}
}
}