.add(new ColumnElement(null, null, content, null));
return this;
}
public HtmlTable build() {
HtmlTable table = new HtmlTable(id, request, response);
table.getTableConfiguration().getExportConfiguration().put(exportConf.getFormat(), exportConf);
if (data != null && data.size() > 0) {
TableConfig.INTERNAL_OBJECTTYPE.setIn(table.getTableConfiguration(), data.get(0).getClass().getSimpleName());
} else {
TableConfig.INTERNAL_OBJECTTYPE.setIn(table.getTableConfiguration(), "???");
}
table.addHeaderRow();
for (HtmlColumn column : headerColumns) {
String title = ColumnConfig.TITLE.valueFrom(column.getColumnConfiguration());
if (StringUtils.isNotBlank(title)) {
column.setContent(new StringBuilder(title));
} else {
column.setContent(new StringBuilder(""));
}
table.getLastHeaderRow().addColumn(column);
}
if (data != null) {
for (T o : data) {
table.addRow();
for (HtmlColumn column : headerColumns) {
String content = "";
for (ColumnElement columnElement : column.getColumnConfiguration().getColumnElements()) {
if (StringUtils.isNotBlank(columnElement.getPropertyName())) {
try {
Object tmpObject = PropertyUtils.getNestedProperty(o, columnElement
.getPropertyName().trim());
if (StringUtils.isNotBlank(columnElement.getPattern())) {
MessageFormat messageFormat = new MessageFormat(columnElement.getPattern());
content += messageFormat.format(new Object[] { tmpObject });
} else {
content += String.valueOf(tmpObject);
}
} catch (Exception e) {
logger.warn("Something went wrong with the property {}. Check that an accessor method for this property exists in the bean.");
content += columnElement.getDefaultValue();
}
} else if (columnElement.getContent() != null) {
content += columnElement.getContent();
} else {
content += columnElement.getDefaultValue();
}
}
table.getLastBodyRow().addColumn(String.valueOf(content));
}
}
}
return table;