質問

私は、カスタムTableDecoratorとJSPで、次のDisplayTagテーブルでソート/外部のページングを使用しています:

<display:table id="ixnlist" name="pageScope.itemList" sort="external"
  decorator="org.mdibl.ctd.pwa.displaytag.decorator.IxnTableWrapper">

   <display:column title="Row" property="rowNum" />

   ...more columns...
</display:table> 

テーブルデコレータで、getListIndex()我々はページごとに100個のオブジェクトを表示している場合にのみ、現在のページにではなく、全体的なリストに行番号の相対を返す(すなわち、その後、getListIndex()はで「0」を返します2ページの最上部ではなく、 "100")。

/**
 * Returns the row number data for the current row.
 *
 * @return String containing row number heading.
 */
public String getRowNum() {
    final StringBuilder out = new StringBuilder(8);
    out.append(nf.format(getListIndex() + 1))
       .append('.');
    return out.toString();
}

これは何とか正しいオフセットを反映した行番号を取得するには、テーブルデコレータで可能ですか?それはページネーションリンクをフォーマットするためにそれを使用するようDisplaytagは、の、オフセットどこかのの認識しています。

displaytagドキュメントはこの質問には対応していませんし、$ {} row_rowNum暗黙オブジェクトはデコレータで)getListIndex(とまったく同じ働きます。

はい、それはページ番号付きのSQLに、行番号の列を追加し、利用可能な場合TableDecoratorがあることを使用したことにより、これを行うことは可能ですが、私はむしろ、メタデータのようなもののためにDAOに頼らないと思います。それが存在する場合、以下のTableDecorator法)(それ以外の場合はgetListIndexを使用し、ROWNUM列を利用する

/**
 * Returns the row number data for the current row.
 *
 * @return String containing row number heading.
 */
public String getRowNum() {
    final StringBuilder out = new StringBuilder(8);
    final Map row = (Map) getCurrentRowObject();

    // Use 'rnum' column for external pagination if it exists.
    // Kludgy way of doing this.
    if (row.get("rnum") != null) {
        out.append(nf.format(row.get("rnum")));
    } else {
        out.append(nf.format(getListIndex() + 1));
    }
    out.append('.');
    return out.toString();
}

感謝します。

/ MCR

役に立ちましたか?

解決

あなたが要求しているページ番号を参照することで、正しい全体的な指標値を計算することができる必要があります。

これはあなたのTableDecoratorクラスのようなコードに何か作業をする必要があります:

public String getIndex() {
   int numItemsPerPage = 100;
   int page = Integer.parseInt(getPageContext().getRequest().getParameter("page"));
   int index = getListIndex();

   return ((page - 1) * numItemsPerPage) + index + 1;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top