WebSphere Application Server for z/OS, Version 6.1   
             オペレーティング・システム: z/OS

             目次と検索結果のパーソナライズ化

例: tsx:repeat JavaServer Pages タグの使用による結果セットでの繰り返し (非推奨)

<tsx:repeat> タグは結果セットで繰り返されます。 結果セットは Bean の中に含まれています。 Bean は静的 Bean (例えば、IBM WebSphere Studio データベース・ウィザードを使用して作られたもの) である場合や、 動的に生成された Bean (例えば、<tsx:dbquery> 構文によって生成されたもの) である場合があります。

非推奨の機能 (Deprecated feature): JavaServer Pages (JSP) エンジンの tsx タグのサポートは、WebSphere Application Server バージョン 6.0 では非推奨です。tsx タグを使用する代わりに、 JavaServer Pages 標準タグ・ライブラリー (JSTL) の同等のタグを使用してください。 depfeat

次の表は、myBean と呼ばれる Bean のコンテンツを表で表現したものです。

  col1 col2 col3
row0 friends Romans countrymen
row1 bacon lettuce tomato
row2 May June July

Bean に関するいくつかの注意点

次の表は、静的 Bean で繰り返される <tsx:repeat> タグを使用する場合と、 動的に生成された Bean を比較したものです。

静的 Bean の例 <tsx:repeat> Bean の例
myBean.class
// Code to get a connection

// Code to get the data
   Select * from myTable;

// Code to close the connection
JSP ファイル
<tsx:repeat index=abc>
  <tsx:getProperty name="myBean"
    property="col1(abc)" />
</tsx:repeat>

注:

  • Bean (myBean.class) は静的 Bean です。
  • Bean プロパティーにアクセスするためのメソッドは、myBean.get(property(index)) です。
  • プロパティー索引は省略することができます。 その場合は、それを囲んでいる <tsx:repeat> タグの索引が使用されます。 また、<tsx:repeat> タグでも索引を省略することができます。
  • <tsx:repeat> タグは、開始行から始まり、行ごとに Bean プロパティーで繰り返されます。
JSP ファイル
<tsx:dbconnect id="conn"
userid="alice"passwd="test"
url="jdbc:db2:sample"
driver="COM.ibm.db2.jdbc.app.DB2Driver">
</tsx:dbconnect>

<tsx:dbquery id="dynamic"
 connection="conn" >
  Select * from myTable;
</tsx:dbquery>

<tsx:repeat index=abc>
  <tsx:getProperty name="dynamic"
    property="col1(abc)" />
</tsx:repeat>

注:

  • Bean (動的) は <tsx:dbquery> タグによって生成され、 その構文が実行されるまでは存在しません。
  • Bean プロパティーにアクセスするためのメソッドは、dynamic.getValue("property", index) です。
  • プロパティー索引は省略することができます。 その場合は、それを囲んでいる <tsx:repeat> タグの索引が使用されます。 また、<tsx:repeat> タグでも索引を省略することができます。
  • <tsx:repeat> タグ構文は、開始行から始まり、行ごとに Bean プロパティーで繰り返されます。

暗黙的および明示的な索引付け

例 1、2、および 3 は 、<tsx:repeat> タグの使用方法を示しています。 これらの例は、索引付きのプロパティーがすべて 300 以下のエレメントを持つ場合には、 同じ出力を作成します。 エレメントが 300 よりも多い場合には、例 1 と 2 はすべてのエレメントを表示しますが、 例 3 は最初の 300 のエレメントだけを表示します。

例 1 は、デフォルトの開始および終了索引を使用した、暗黙の索引付け を示しています。 最も小さい番号の索引付きプロパティーを持つ Bean により、ループの反復回数が制限されます。

<table>
<tsx:repeat>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" />
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address" />
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone" />
  </tr></td>
</tsx:repeat>
</table>

例 2 は、索引付け、開始索引、および終了索引を示しています。

<table>
<tsx:repeat index=myIndex start=0 end=2147483647>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property=city(myIndex) />
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property=address(myIndex) />
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property=telephone(myIndex) />
</tr></td>
</tsx:repeat>
</table>

例 3 は、明示的な索引付け および終了索引と、暗黙の開始索引を示しています。 index 属性が指定されていますが、(myIndex) タグが必要ないため、 索引付きプロパティー city は暗黙的に索引付けすることができます。

<table>
<tsx:repeat index=myIndex end=299>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" /t>
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address(myIndex)" />
  </tr></td>
  <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone(myIndex)" />
  </tr></td>
</tsx:repeat>
</table>

<tsx:repeat> ブロックのネスティング

<tsx:repeat> ブロックをネストできます。 各ブロックは個別に索引付けされます。 この機能は、2 つの Bean でプロパティーをインターリーブする場合、 あるいはサブプロパティーを持つプロパティーをインターリーブする場合に便利です。 例では、2 つの <tsx:repeat> ブロックがネストされてユーザーのショッピング・カートの中にあるそれぞれの CD に入っている歌のリストを表示します。

<tsx:repeat index=cdindex>
  <h1><tsx:getProperty name="shoppingCart" property=cds.title /></h1>
  <table>
  <tsx:repeat>
    <tr><td><tsx:getProperty name="shoppingCart" property=cds(cdindex).playlist />
    </td></tr>
  </tsx:repeat>
  </table>
 </tsx:repeat>



関連概念
JavaServer Pages
関連タスク
インストール済みオプション・パッケージの使用
共用ライブラリーの管理
関連資料
Web アプリケーション: 学習用リソース
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 9:12:22 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/rweb_jrepr.html