次のようなデータを含むトランザクションのテーブルがあります。DATETIME形式はdd/MM/yyyyです。
+ ------ + ------------------- + ---------------- + ----- --- + | ID | START_DATETIME | END_DATETIME | ユーザー| + ------ + ------------------- + ---------------- + ----- --- + | 1 | 2012年1月1日00:00|2012年1月1日01:00| ボブ| + ------ + ------------------- + ---------------- + ----- --- + | 2 | 2012年2月1日00:00|2012年2月1日01:00| foo | + ------ + ------------------- + ---------------- + ----- --- +
1日以内に、複数のトランザクションが発生する可能性があります。エンドユーザーの場合、以下のデータテーブルのように、トランザクションを日ごとにグループ化したいと思います。
+ ------ + --------------- + ------------ + ---------- +- ----- + | ID | START_TIME | END_TIME | 期間| ユーザー| + ------ + --------------- + ------------ + ---------- +- ----- + | 2012年1月1日日曜日| + ------ + --------------- + ------------ + ---------- +- ----- + | 1 | 00:00 | 01:00 | 01:00 | ボブ| + ------ + --------------- + ------------ + ---------- +- ----- + | 2012年1月2日月曜日| + ------ + --------------- + ------------ + ---------- +- ----- + | 2 | 00:00 | 01:00 | 01:00 | foo | + ------ + --------------- + ------------ + ---------- +- ----- +
JSF 2.0のデータテーブルでこれを行うにはどうすればよいですか?カスタムコンポーネントを作成する必要がありますか?
サービスレイヤーは、次のようなトランザクションを提供します。java.util.List<Transaction>
class Transaction {
private int id;
private Date start;
private Date end;
private User user;
// getters and setters ...
}
編集:
chkalの答えに基づいて、これが私が思いついた解決策です
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Group by day</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th colspan="4">The last 10 transactions</th>
</tr>
<tr>
<th>ID</th>
<th>START DATE</th>
<th>END DATE</th>
<th>USER</th>
</tr>
</thead>
<!-- Firstly iterate other dates -->
<ui:repeat value="#{transactionBean.distinctTransactionsDates}" var="entry">
<tbody>
<tr>
<th colspan="4" align="left"><h:outputText value="#{entry}" /></th>
</tr>
<!-- Secondly iterate other transactions -->
<ui:repeat var="t" value="#{transactionBean.getTransactionList(entry)}">
<tr>
<td><h:outputText value="#{t.id}" /></td>
<td><h:outputText value="#{t.startDate}" /></td>
<td><h:outputText value="#{t.endDate}" /></td>
<td><h:outputText value="#{t.user}" /></td>
</tr>
</ui:repeat>
</tbody>
</ui:repeat>
</table>
</body>
</html>
出力
<table border="1">
<thead>
<tr>
<th colspan="4">The last 10 transactions</th>
</tr>
<tr>
<th>ID</th>
<th>START DATE</th>
<th>END DATE</th>
<th>USER</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="4" align="left">Sun Jan 01 00:00:00 CET 2012</th>
</tr>
<tr>
<td>1</td>
<td>Sun Jan 01 00:00:00 CET 2012</td>
<td>Sun Jan 01 01:00:00 CET 2012</td>
<td>bob</td>
</tr>
<!-- Other rows appear here -->
</tbody>
<!-- Other tbodies appear here -->
</table>
注 ui:repeat
はJSF2.0の新機能です。詳細についてはh:dataTable
、
このチュートリアルをチェックアウトする代わりに使用できます。