なんかトリッキーなコードになってしまった…
そーゆー使い方はするなってことか?
ページ
public class Index extends Page {private Database dbh = null;
public Table table = new Table();
public ActionButton selector = new ActionButton("selector", this, "onSelectorClick");
private String selected = null;
public Index(Database dbh) {
this.dbh = dbh;table.setAttribute("class", "simple");
table.addColumn(new Column("cursor", "--"));
table.addColumn(new Column(Book.ISBN.getName(), "ISBN"));
table.addColumn(new Column(Book.TITLE.getName(), "タイトル"));
table.addColumn(new Column(Book.AUTHOR.getName(), "著者"));
table.addColumn(new Column(Category.NAME.getName(), "カテゴリ"));
table.addColumn(new Column(selector.getName(), "-----"));selector.setLabel("選択");
}public void onRender() {
final List books = new ArrayList();Book.join(Category.class).findAny(dbh, Book.ISBN.order_by(), 0, 5, new Handler() {
public void handle(Book book, Category category) {
Map row = new HashMap();row.put("cursor", book.getIsbn().equals(selected) ? "⇒" : "");
book.putIsbn(row);
book.putTitle(row);
book.putAuthor(row);
category.putName(row);ActionButton b = button(book.getIsbn());
row.put(b.getName(), b);books.add(row);
}
});table.setRowList(books);
}private ActionButton button(String isbn) {
ActionButton b = new ActionButton(selector.getName(), "選択");
b.setContext(getContext());
b.setValue(isbn);
return b;
}public boolean onSelectorClick() {
selected = selector.getValue();
return true;
}}
テンプレート
<html>
<head>
$imports
</head>
<body>
$table
</body>
</html>