チュートリアル4(配列化)

TABLEの扱い

引き続き、一覧部分をコーディングします。SeekHtmlクラスに新しくメソッドを作ります。

tutorial2/logic/SeekHtml.java①
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
    /**
     * 一覧の作成。
     * @param start 表示開始データ。
     * @param end 表示終了データ。
     */
    private void makeTable( int start, int end ) {
        Table   table = getListTable();
        table.removeLine( 1, -1 );
        int count = end - start + 1;
        for ( int i = 0; i < count; i++ ) {
            User    user = User.db.get( start + i );
            Line    line = (Line)org_line.getReplica();
            line.setValueString(
                0,
                Integer.toString( i + 1 ),
                user.user_id,
                user.name,
                user.sex.equals( "m" )? "男性": "女性",
                user.address
            );
            table.addLine( line );
        }
    }

outputMainから、このメソッドを呼び出します。

tutorial2/logic/SeekHtml.java②
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
    public Page outputMain( Page from, RequestParameter req ) throws PageException {
        // 出力内容を設定します。
        // 初期化したい場合は、init()をコールして下さい。
 
        if ( from.getID() != tutorial2.base.PageType.MENU_HTML ) {
            // 全件の数
            int data_count = User.db.size();
            if ( data_count > 0 && getUserIdInput().isEmptyValue() ) {
                // ユーザーIDが空欄なら全件表示
                getNotFoundP().setVisible( false );
                getResultDiv().setVisible( true );
 
                // 総ページ数の算出。
                int page_count = (data_count + MAX_LINE - 1) / MAX_LINE;
                // このページの開始データ。
                int start = page * MAX_LINE;
                // このページの終了データ。
                int end = start + MAX_LINE - 1;
                if ( end >= data_count )    end = data_count - 1;
 
                // ページリンク作成
                try {
                    makePageLink( getPageTopSpan(), page_count );
                    makePageLink( getPageBottomSpan(), page_count );
                }
                catch( Exception e ) {
                    throw new PageException( e );
                }
 
                // 一覧表示
                makeTable( start, end );
            }
            else {
                // ユーザーIDに何か入っていれば0件表示
                getNotFoundP().setVisible( true );
                getResultDiv().setVisible( false );
            }
        }
        return this;
    }

コントロールの配列化

この状態で、全件検索結果をブラウザから見てみます。

ユーザーID  
1   2   3   次へ
No ユーザーID 名前 性別 住所  
1 user0 チュートリアル 男性 京都  
2 user1 康介 男性 北京  
3 user2 宮里 女性 沖縄  
1   2   3   次へ


戻る

検索画面
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
<html><head>
<meta content="text/css" http-equiv="Content-Style-Type">
<title>ユーザー一覧</title></head>
<body background=".//image/wallpaper.gif">
      <FORM action="lu.vtneod.mo.xjmhm9.on.xjmhm9.na" method="post">
        <INPUT name="paraselene$form" value="i" type="hidden">
        ユーザーID <INPUT name="user_id" value="" type="text" size="20"> &nbsp;
        <INPUT name="seek" value="検索" type="submit">
      </FORM>
      <FORM action="lu.vtneoe.mo.xjmhm9.on.xjmhm9.na" method="post">
        <INPUT name="paraselene$form" value="j" type="hidden">
        <DIV name="result">
        <SPAN name="page_top">
          <B>1</B> &nbsp;
          <A href="lu.vtneof.mo.xjmhm9.on.xjmhm9.na?page=1">2</A> &nbsp;
          <A href="lu.vtneog.mo.xjmhm9.on.xjmhm9.na?page=2">3</A> &nbsp;
          <A href="lu.vtneoh.mo.xjmhm9.on.xjmhm9.na?page=1">次へ</A>
        </SPAN>
      <TABLE name="list" border="1">
          <TR>
            <TD bgcolor="#00CCCC">No</TD>
            <TD bgcolor="#00CCCC">ユーザーID</TD>
            <TD bgcolor="#00CCCC">名前</TD>
            <TD bgcolor="#00CCCC">性別</TD>
            <TD bgcolor="#00CCCC">住所</TD>
            <TD bgcolor="#00CCCC">&nbsp;</TD>
          </TR>
          <TR>
            <TD align="right">1</TD>
            <TD>user0</TD>
            <TD>チュートリアル</TD>
            <TD>男性</TD>
            <TD>京都</TD>
            <TD><INPUT name="edit$3" value="編集" type="submit">&nbsp;
              <INPUT name="delete$3" value="削除" type="submit"></TD>
          </TR>
          <TR>
            <TD align="right">2</TD>
            <TD>user1</TD>
            <TD>康介</TD>
            <TD>男性</TD>
            <TD>北京</TD>
            <TD><INPUT name="edit$4" value="編集" type="submit">&nbsp;
              <INPUT name="delete$4" value="削除" type="submit"></TD>
          </TR>
          <TR>
            <TD align="right">3</TD>
            <TD>user2</TD>
            <TD>宮里</TD>
            <TD>女性</TD>
            <TD>沖縄</TD>
            <TD><INPUT name="edit$5" value="編集" type="submit">&nbsp;
              <INPUT name="delete$5" value="削除" type="submit"></TD>
          </TR>
      </TABLE>
      <SPAN name="page_bottom">
        <B>1</B> &nbsp;
        <A href="lu.vtneoi.mo.xjmhm9.on.xjmhm9.na?page=1">2</A> &nbsp;
        <A href="lu.vtneoj.mo.xjmhm9.on.xjmhm9.na?page=2">3</A> &nbsp;
        <A href="lu.vtneok.mo.xjmhm9.on.xjmhm9.na?page=1">次へ</A>
      </SPAN>
      </DIV>
      <BR><BR>
      <INPUT name="new" value="新規追加" type="submit"></FORM>
      <P><A href="lu.vtneol.mo.xjmhm9.on.svvxoa.na">戻る</A></P>
</body></html>

チュートリアル5(検索入力)

最終更新: 2009/10/31
特に明示されていない限り、本Wikiの内容は次のライセンスに従います:CC Attribution 3.0 Unported
文書の先頭へ
SourceForge.JP
2009 © Akira Terasaki.  
Driven by DokuWiki The Apache Software Foundation