LittleSoft J-Programming
3.4.4. ページング
この章では、WebSQL テーブルオブジェクトのページ切り替えを行う手順について説明します。

WebSQL テーブルオブジェクトのページング設定をする
WebSQL テーブルオブジェクトのページング設定を行います。
/* コンストラクタ */
public EmpPage(HttpServletRequest request,
HttpServletResponse response) throws Exception {
…
// 1 ページあたりの表示行数を設定
tableEmp.setShowRows(5);
…
}
public EmpPage(HttpServletRequest request,
HttpServletResponse response) throws Exception {
…
// 1 ページあたりの表示行数を設定
tableEmp.setShowRows(5);
…
}
ページング設定をする(「 setShowRows 」メソッド)
Velocity テンプレートに一覧表示する際の行数を指定します。ActionPage クラスにアクションメソッドを追加する
ActionPage クラスに画面から呼び出すアクションメソッドを追加します。
/最後のページ」へ、「 setShowRows 」メソッドで設定した行数毎にスクロールすることができます。
/* 一覧に表示する内容をページングします。 */
public void paging(String direction) throws Exception {
// 最初のページへ
if ("first".equals(direction)) {
tableEmp.pageFirst();
}
// 前のページへ
else if ("prev".equals(direction)) {
tableEmp.pagePrevious();
}
// 次のページへ
else if ("next".equals(direction)) {
tableEmp.pageNext();
}
// 最後のページへ
else if ("last".equals(direction)) {
tableEmp.pageLast();
}
// 再表示
show();
}
public void paging(String direction) throws Exception {
// 最初のページへ
if ("first".equals(direction)) {
tableEmp.pageFirst();
}
// 前のページへ
else if ("prev".equals(direction)) {
tableEmp.pagePrevious();
}
// 次のページへ
else if ("next".equals(direction)) {
tableEmp.pageNext();
}
// 最後のページへ
else if ("last".equals(direction)) {
tableEmp.pageLast();
}
// 再表示
show();
}
ページングする(「 pageFirst / pagePrevious / pageNext / pageLast 」メソッド)
各メソッドを使用して、WebSQL テーブルオブジェクトを「最初のページ/前のページ/次のページ/最後のページ」へ、「 setShowRows 」メソッドで設定した行数毎にスクロールすることができます。
HTML テンプレートに ActionPage 連携用の記述を追加する
HTML テンプレートにアクションメソッドを呼び出す記述を追加します。
<!-- ページ遷移ボタンを配置 -->
<input type="button" value="最初のページ"
onclick="ls.exec('paging','first')" #if(!$tableEmp.hasPrevPage) disabled #end />
<input type="button" value="前のページ"
onclick="ls.exec('paging','prev')" #if(!$tableEmp.hasPrevPage) disabled #end />
<input type="button" value="次のページ"
onclick="ls.exec('paging','next')" #if(!$tableEmp.hasNextPage) disabled #end />
<input type="button" value="最後のページ"
onclick="ls.exec('paging','last')" #if(!$tableEmp.hasNextPage) disabled #end />
<input type="button" value="最初のページ"
onclick="ls.exec('paging','first')" #if(!$tableEmp.hasPrevPage) disabled #end />
<input type="button" value="前のページ"
onclick="ls.exec('paging','prev')" #if(!$tableEmp.hasPrevPage) disabled #end />
<input type="button" value="次のページ"
onclick="ls.exec('paging','next')" #if(!$tableEmp.hasNextPage) disabled #end />
<input type="button" value="最後のページ"
onclick="ls.exec('paging','last')" #if(!$tableEmp.hasNextPage) disabled #end />
「 $tableEmp.hasPrevPage / hasNextPage 」
現在表示しているページよりも前/後のページが存在するか否かを表します。ページを表示する
ボタンをクリックして、表示しているページが切り替わることを確認します。