Displaytag external paging / sorting and getting true line number

I use external paging / sorting using the special TableDecorator and the following DisplayTag table in JSP:

<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> 

In the table decorator, getListIndex () returns a line number that applies only to the current page, and not to the general list (i.e. if we show 100 objects per page, then getListIndex () returns "0" at the top of page 2, not " one hundred" ).

/**
 * 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();
}

Is it possible in the table decorator to somehow get the row number reflecting the correct shift? Displaytag is aware of some kind of bias because it uses it to format page links.

Displaytag docs don't solve this issue, and the implicit $ {row_rowNum} object works the same way with getListIndex () in the decorator.

, , SQL TableDecorator, , DAO . TableDecorator rownum, , getListIndex():

/**
 * 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

+3
1

, , .

TableDecorator:

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

   return ((page - 1) * numItemsPerPage) + index + 1;
}
+1

Source: https://habr.com/ru/post/1709991/


All Articles