gpt4 book ai didi

java - displaytag 外部分页/排序并获取真实行号

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:23 28 4
gpt4 key购买 nike

我在 JSP 中使用自定义 TableDecorator 和以下 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();
}

是否有可能在表格装饰器中以某种方式获得反射(reflect)正确偏移量的行号? Displaytag 知道某处的偏移量,因为它使用它来格式化分页链接。

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

关于java - displaytag 外部分页/排序并获取真实行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/965198/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com