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

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

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

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

表 1. myBean のグラフィック表現。. myBean のコンテンツです。
col1 col2 col3
row0 friends Romans countrymen
row1 bacon lettuce tomato
row2 May June July

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

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

表 2. 静的 Bean および <tsc:repeat> Bean の例. この表を使用して、2 つの 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>

トピックのタイプを示すアイコン 参照トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rweb_jrepr
ファイル名:rweb_jrepr.html