ActionButtonを使ったActionTable

ActionLinkを使った例しかないので。

ページ


public class Index extends Page {

private Database dbh = null;

public ActionButton select = new ActionButton(this, "onSelectClick");

public String selected = "";

public Index(Database dbh) {
this.dbh = dbh;
select.setLabel("選択");
}

public void onRender() {
model.remove("books");
addModel("books", Book.findAny(dbh, Book.ISBN.order_by(), 0, 5));
}

public boolean onSelectClick() {
selected = select.getValue();
return true;
}

}

テンプレート

コードがアレゲなのはさておき。
#set($select.value = $book.isbn)」がイマイチ。
setValue()でActionButtonを返してくれるともう少しきれいに書けそうだけど。


<html>
<head>
$imports
</head>
<body>
<table border="1">
<tr>
<th>ISBN</th>
<th>タイトル</th>
<th>著者</th>
<th>-----</th>
</tr>
#foreach($book in $books)
#set($select.value = $book.isbn)
#if($book.isbn == $selected)
<tr bgcolor="blue">
#else
<tr>
#end
<td>$book.isbn</td>
<td>$book.title</td>
<td>$book.author</td>
<td>$select</td>
</tr>
#end
</table>
</body>
</html>

で…