final boolean ie6SelectOneFix = showHeader
&& ClientProperties.getInstance(facesContext).getUserAgent().isMsie6()
&& ComponentUtils.findDescendant(sheet, UISelectOne.class) != null;
// BEGIN RENDER BODY CONTENT
Style bodyStyle = new Style();
bodyStyle.setPosition(Position.RELATIVE);
Measure tableBodyWidth = sheet.getCurrentWidth().subtractNotNegative(getContentBorder(facesContext, sheet));
bodyStyle.setWidth(tableBodyWidth);
if (sheet.isPagingVisible()) {
sheetHeight = sheetHeight.subtract(footerHeight);
}
if (ie6SelectOneFix) {
bodyStyle.setTop(headerHeight);
}
if (showHeader) {
sheetHeight = sheetHeight.subtract(headerHeight);
}
bodyStyle.setHeight(sheetHeight);
writer.startElement(HtmlElements.DIV, null);
writer.writeIdAttribute(sheetId + ComponentUtils.SUB_SEPARATOR + "data_div");
writer.writeClassAttribute(Classes.create(sheet, "body"));
if (!showHeader || ie6SelectOneFix) {
bodyStyle.setPaddingTop(Measure.ZERO);
}
writer.writeStyleAttribute(bodyStyle);
bodyStyle.setHeight(null);
bodyStyle.setTop(null);
Style sheetBodyStyle = new Style(bodyStyle);
final boolean needVerticalScrollbar = needVerticalScrollbar(facesContext, sheet, style);
if (needVerticalScrollbar) {
tableBodyWidth = tableBodyWidth.subtractNotNegative(getVerticalScrollbarWeight(facesContext, sheet));
}
sheetBodyStyle.setWidth(tableBodyWidth);
writer.startElement(HtmlElements.TABLE, null);
writer.writeAttribute(HtmlAttributes.CELLSPACING, 0);
writer.writeAttribute(HtmlAttributes.CELLPADDING, 0);
writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);
writer.writeClassAttribute(Classes.create(sheet, "bodyTable"));
writer.writeStyleAttribute(sheetBodyStyle);
if (columnWidths != null) {
writer.startElement(HtmlElements.COLGROUP, null);
for (Integer columnWidth : columnWidths) {
writer.startElement(HtmlElements.COL, null);
writer.writeAttribute(HtmlAttributes.WIDTH, columnWidth);
writer.endElement(HtmlElements.COL);
}
writer.endElement(HtmlElements.COLGROUP);
}
// Print the Content
if (LOG.isDebugEnabled()) {
LOG.debug("first = " + sheet.getFirst() + " rows = " + sheet.getRows());
}
final String var = sheet.getVar();
boolean odd = false;
boolean emptySheet = true;
// rows = 0 means: show all
final int last = sheet.hasRows() ? sheet.getFirst() + sheet.getRows() : Integer.MAX_VALUE;
for (int rowIndex = sheet.getFirst(); rowIndex < last; rowIndex++) {
sheet.setRowIndex(rowIndex);
if (!sheet.isRowAvailable()) {
break;
}
emptySheet = false;
odd = !odd;
if (LOG.isDebugEnabled()) {
LOG.debug("var " + var);
LOG.debug("list " + sheet.getValue());
}
writer.startElement(HtmlElements.TR, null);
Markup rowMarkup = odd ? Markup.ODD : Markup.EVEN;
if (selectedRows.contains(rowIndex)) {
rowMarkup = rowMarkup.add(Markup.SELECTED);
}
writer.writeClassAttribute(Classes.create(sheet, "row", rowMarkup));
if (rowIndex == sheet.getFirst()) {
writer.writeAttribute("rowIndexInModel", Integer.toString(sheet.getFirst()), false);
}
int columnIndex = -1;
for (UIColumn column : renderedColumnList) {
columnIndex++;
writer.startElement(HtmlElements.TD, column);
Markup markup = column instanceof SupportsMarkup ? ((SupportsMarkup) column).getMarkup() : Markup.NULL;
if (markup == null) {
markup = Markup.NULL;
}
if (columnIndex == 0) {
markup = markup.add(Markup.FIRST);
}
if (hasClickAction) {
markup = markup.add(Markup.CLICKABLE);
}
if (isPure(column)) {
markup = markup.add(Markup.PURE);
}
writer.writeClassAttribute(Classes.create(sheet, "cell", markup));
final TextAlign align = TextAlign.parse((String) column.getAttributes().get(Attributes.ALIGN));
if (align != null) {
Style alignStyle = new Style();
alignStyle.setTextAlign(align);
writer.writeStyleAttribute(alignStyle);
}
if (column instanceof UIColumnSelector) {
final boolean disabled = ComponentUtils.getBooleanAttribute(column, Attributes.DISABLED);
writer.startElement(HtmlElements.INPUT, null);
writer.writeAttribute(HtmlAttributes.TYPE, "checkbox", false);
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
writer.writeIdAttribute(sheetId + "_data_row_selector_" + rowIndex);
writer.writeClassAttribute(Classes.create(sheet, "columnSelector"));
writer.endElement(HtmlElements.INPUT);
} else {
List<UIComponent> children = sheet.getRenderedChildrenOf(column);
for (UIComponent grandKid : children) {
// set height to 0 to prevent use of layoutheight from parent
grandKid.getAttributes().put(Attributes.LAYOUT_HEIGHT, HEIGHT_0);
// XXX hotfix
if (grandKid instanceof LayoutBase) {
LayoutBase base = (LayoutBase) grandKid;
if (base.getLeft() != null) {
base.setLeft(null);
}
if (base.getTop() != null) {
base.setTop(null);
}
}
RenderUtils.prepareRendererAll(facesContext, grandKid);
RenderUtils.encode(facesContext, grandKid);
}
}
writer.endElement(HtmlElements.TD);
}
writer.startElement(HtmlElements.TD, null);
writer.writeClassAttribute(Classes.create(sheet, "cell"));
writer.write(" ");
writer.endElement(HtmlElements.TD);
writer.endElement(HtmlElements.TR);
}
sheet.setRowIndex(-1);
if (emptySheet && showHeader) {
writer.startElement(HtmlElements.TR, null);
int columnIndex = -1;
for (UIColumn column : renderedColumnList) {
columnIndex++;
writer.startElement(HtmlElements.TD, null);
writer.startElement(HtmlElements.DIV, null);
Integer divWidth = sheet.getWidthList().get(columnIndex);
Style divStyle = new Style();
divStyle.setWidth(Measure.valueOf(divWidth));
writer.writeStyleAttribute(divStyle);
writer.endElement(HtmlElements.DIV);
writer.endElement(HtmlElements.TD);
}
writer.startElement(HtmlElements.TD, null);
writer.writeClassAttribute(Classes.create(sheet, "cell"));
writer.write(" ");
writer.endElement(HtmlElements.TD);
writer.endElement(HtmlElements.TR);
}
writer.endElement(HtmlElements.TABLE);
writer.endElement(HtmlElements.DIV);
// END RENDER BODY CONTENT
if (showHeader) {
renderColumnHeaders(
facesContext, sheet, writer, resourceManager, contextPath, sheetId, renderedColumnList, tableBodyWidth);
}
if (sheet.isPagingVisible()) {
Style footerStyle = new Style();
footerStyle.setWidth(sheet.getCurrentWidth());
footerStyle.setHeight(footerHeight);
if (ie6SelectOneFix) {
footerStyle.setTop(headerHeight);
}
writer.startElement(HtmlElements.DIV, sheet);
writer.writeClassAttribute(Classes.create(sheet, "footer"));
writer.writeStyleAttribute(footerStyle);