僕のコードは間抜けだけど、Clickはすげー。
[ページ]
[テンプレート]public class Index extends Page {
public ActionButton prev = new ActionButton(this, "onPrevClick");
public ActionButton next = new ActionButton(this, "onNextClick");
private int start = 0;
private static final int LINES = 5;
private Database dbh = null;public Index(Database dbh) {
this.dbh = dbh;
}public void onRender() {
model.remove("rows");
Map[] rows = Book.join(Category.class).findAny(dbh, Book.ISBN.order_by(), start, LINES);
addModel("rows", rows);prev.setValue(String.valueOf(start - LINES));
next.setValue(String.valueOf(start + LINES));
}public boolean onPrevClick() {
int prev_start = prev.getValueInteger().intValue();
start = (prev_start >= 0) ? prev_start : 0;
return true;
}public boolean onNextClick() {
int next_start = next.getValueInteger().intValue();
start = (next_start < Book.count(dbh)) ? next_start : (next_start - LINES);
return true;
}}
<html>
<body>
$prev $next<br><br>
#foreach($row in $rows)
$row.book.title<br>
$row.category.name<br>
<br>
#end
</body>
</html>
フォームなしでボタン使えるのもいいし、フィールド名がそそまま変数名になるのも楽だし。