displaytag外部分页/排序和获取真实的行号
-
12-09-2019 - |
题
我使用外部寻呼/与自定义TableDecorator排序和以下DisplayTag表格不同的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>
在表装饰,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 是意识到偏移某处的,因为它使用它来格式化分页链接。
由标签文档没有解决这个问题,和$ {row_rowNum}隐式对象在装饰工作相同地getListIndex()。
是的,它可以通过添加行号列的分页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
解决方案
您应该能够通过参考页号是在所述请求计算正确的总索引值。
代码这样的事情你TableDecorator
类应该工作:
public String getIndex() {
int numItemsPerPage = 100;
int page = Integer.parseInt(getPageContext().getRequest().getParameter("page"));
int index = getListIndex();
return ((page - 1) * numItemsPerPage) + index + 1;
}
不隶属于 StackOverflow