'What is the best way to show a table in a view using PlayFramework 1.5.*?
I'm doing a play framework 1.5.* project, and I need to display some tables, that I get from a mysql database, in a view. I need to display more than one table and the way I'm currently doing it (see below) seems to complicated, and that is just for one table. Is there a better way?
public static void listEntities() {
Item i = new Item();
List<String> headers = new ArrayList<String>();
List<Integer> id = new ArrayList<Integer>();
List<String> item = new ArrayList<String>();
List<Integer> quantity = new ArrayList<Integer>();
List<Integer> range = new ArrayList<Integer>();
headers.add("Id");
headers.add("Item Name");
headers.add("Quantity");
try {
ResultSet rs = i.getTableData();
rs.first();
do {
id.add(rs.getInt(1));
item.add(rs.getString(2));
quantity.add(rs.getInt(3));
} while (rs.next());
} catch (SQLException e) {
System.out.println(e.getMessage());
}
for(int k=0; k < id.size(); k++){
range.add(k);
}
render(headers, id, item, quantity, range);
}
<table style="width:100%">
<tr>
%{
for(h in headers ) {
}%
<th>${h}</th>
%{
}
}%
</tr>
%{
for(i in range) {
}%
<tr>
<td>${id.get(i)}</td>
<td>${item.get(i)}</td>
<td>${quantity.get(i)}</td>
</tr>
%{
}
}%
</tr>
</table>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
