final Iterable<?> data = (Iterable<?>) args.remove("arg");
if (data == null) {
throw new TemplateExecutionException(template.template,
fromLine,
"Please specify the data to display",
new TagInternalException("Please specifiy the data to display"));
}
// Ensure data are not empty
if (!data.iterator().hasNext()) {
out.println(Messages.get("table.nodata"));
return;
}
TableContentPrinter contentPrinter;
if (body == null) {
// Automatically fill the table content with the models properties
final Iterable<? extends Model> modelData = (Iterable<? extends Model>)data;
final Class<? extends Model> clazz = modelData.iterator().next().getClass();
if (Model.class.isAssignableFrom(clazz)) {
Map<String, String> properties;
if (args.containsKey("columns")) {
properties = (Map<String, String>)args.remove("columns");
} else {
// Display all properties
properties = new LinkedHashMap<String, String>();
for(Model.Property property : Model.Manager.factoryFor(clazz).listProperties()) {
properties.put(property.name, Messages.get(property.name));
}
}
contentPrinter = new ModelPrinter(properties);
} else {
throw new TemplateExecutionException(template.template,
fromLine,
"Please use Play! models in the 'table' tag",
new TagInternalException("Please use Play! models in the 'table' tag"));
}
} else {
// Fill the table content with the execution of its body
final String it = (String) args.remove("as");
if (it == null) {
throw new TemplateExecutionException(template.template,
fromLine,
"Missing parameter 'as'",
new TagInternalException("Missing parameter 'as'"));
}
contentPrinter = new TagPrinter(body, it);
}
// Handle the optional “rowClass” parameter