* nextapp.echo2.app.update.ServerComponentUpdate, org.w3c.dom.Node, nextapp.echo2.app.Component)
*/
public void renderHtml(RenderContext rc, ServerComponentUpdate update, Node parentNode, Component component) {
ServerMessage serverMessage = rc.getServerMessage();
serverMessage.addLibrary(TABLE_SERVICE.getId());
Table table = (Table) component;
renderInitDirective(rc, table);
Border border = (Border) table.getRenderProperty(Table.PROPERTY_BORDER);
Extent borderSize = border == null ? null : border.getSize();
String elementId = ContainerInstance.getElementId(table);
Document document = parentNode.getOwnerDocument();
Element tableElement = document.createElement("table");
tableElement.setAttribute("id", elementId);
CssStyle tableCssStyle = new CssStyle();
tableCssStyle.setAttribute("border-collapse", "collapse");
if (((Boolean) table.getRenderProperty(Table.PROPERTY_SELECTION_ENABLED, Boolean.FALSE)).booleanValue()) {
tableCssStyle.setAttribute("cursor", "pointer");
}
Insets tableInsets = (Insets) table.getRenderProperty(Table.PROPERTY_INSETS);
String defaultInsetsAttributeValue = tableInsets == null ? "0px" : InsetsRender.renderCssAttributeValue(tableInsets);
ColorRender.renderToStyle(tableCssStyle, component);
FontRender.renderToStyle(tableCssStyle, component);
BorderRender.renderToStyle(tableCssStyle, border);
if (borderSize != null) {
if (!rc.getContainerInstance().getClientProperties().getBoolean(
ClientProperties.QUIRK_CSS_BORDER_COLLAPSE_INSIDE)) {
tableCssStyle.setAttribute("margin", ExtentRender.renderCssAttributeValueHalf(borderSize));
}
}
Extent width = (Extent) table.getRenderProperty(Table.PROPERTY_WIDTH);
boolean render100PercentWidthWorkaround = false;
if (rc.getContainerInstance().getClientProperties().getBoolean(
ClientProperties.QUIRK_IE_TABLE_PERCENT_WIDTH_SCROLLBAR_ERROR)) {
if (width != null && width.getUnits() == Extent.PERCENT && width.getValue() == 100) {
width = null;
render100PercentWidthWorkaround = true;
}
}
ExtentRender.renderToStyle(tableCssStyle, "width", width);
tableElement.setAttribute("style", tableCssStyle.renderInline());
parentNode.appendChild(tableElement);
TableColumnModel columnModel = table.getColumnModel();
int columnCount = columnModel.getColumnCount();
boolean someColumnsHaveWidths = false;
for (int i = 0; i < columnCount; ++i) {
if (columnModel.getColumn(i).getWidth() != null) {
someColumnsHaveWidths = true;
}
}
if (someColumnsHaveWidths) {
Element colGroupElement = document.createElement("colgroup");
tableElement.appendChild(colGroupElement);
for (int i = 0; i < columnCount; ++i) {
Element colElement = document.createElement("col");
Extent columnWidth = columnModel.getColumn(i).getWidth();
if (columnWidth != null) {
colElement.setAttribute("width", ExtentRender.renderCssAttributeValue(columnWidth));
}
colGroupElement.appendChild(colElement);
}
}
Element tbodyElement = document.createElement("tbody");
tbodyElement.setAttribute("id", elementId + "_tbody");
tableElement.appendChild(tbodyElement);
Element firstTrElement = null;
if (table.isHeaderVisible()) {
firstTrElement = renderRow(rc, update, tbodyElement, table, Table.HEADER_ROW, defaultInsetsAttributeValue);
}
int rows = table.getModel().getRowCount();
for (int rowIndex = 0; rowIndex < rows; ++rowIndex) {
if (firstTrElement == null && rowIndex == 0) {
firstTrElement = renderRow(rc, update, tbodyElement, table, rowIndex, defaultInsetsAttributeValue);
} else {
renderRow(rc, update, tbodyElement, table, rowIndex, defaultInsetsAttributeValue);