try {
ResultSetMetaData metaData = resultSet.getMetaData();
String columns = "";
for (int i = 1; i <= metaData.getColumnCount(); i++) {
UIColumn column = (UIColumn) application.createComponent(UIColumn.COMPONENT_TYPE);
String name = metaData.getColumnName(i);
int displaySize = metaData.getColumnDisplaySize(i);
if (i > 1) {
columns += ";";
}
if (displaySize < 10) {
columns += "1*";
} else if (displaySize < 20) {
columns += "2*";
} else {
columns += "4*";
}
if (metaData.getColumnType(i) == Types.INTEGER || metaData.getColumnType(i) == Types.FLOAT) {
column.setAlign("right");
}
column.setLabel(name);
String ref = "#{" + table.getVar() + "." + name + "}";
ValueBinding binding = application.createValueBinding(ref);
if (name.equals("NAME")) {
UICommand command = (UICommand) application.createComponent(UICommand.COMPONENT_TYPE);
command.setRendererType("Link");
command.setValueBinding("label", binding);
MethodBinding action = application.createMethodBinding("#{test.select}", new Class[0]);
command.setAction(action);
column.getChildren().add(command);
} else {
UIOutput output = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
output.setValueBinding("value", binding);
column.getChildren().add(output);
}
table.getChildren().add(column);
}
table.setColumns(columns);