用 Pager-taglib做分页。 在action 里有参数 开始索引号startIndex 一共数据个数total。
在用Pager-taglib 时,页面 按 下一页,没有反应。总是显示第一页的数据。
我不明白的是,怎么把startindex值传到 叶面 上
代码
maxPageItems="7" maxIndexPages="10"
export="pageOffset=startIndex,pageNumber=pageSize" >
我在底层用的是DetachedCriteria做的查询。
这个就是在网上一艘一大把的那个分页。
http://www.iteye.com/topic/14657?page=1
在struts2的action 里能得到 这些参数
ps.getItems()得到已分页好的结果集
ps.getIndexes()得到分页索引的数组
ps.getTotalCount()得到总结果数
ps.getStartIndex()当前分页索引
ps.getNextIndex()下一页索引
ps.getPreviousIndex()上一页索引
就是export="pageOffset=startIndex,pageNumber=pageSize" 这个地方我不知道怎么写。
我这么些,报错 pg:pager TagExtraInfo isValid() == false
help help
[b]问题补充:[/b]
ThinkingInAll 赫赫谢谢你呀。
最近休息了,没有上网。
不是我小气,是因为我现在没有几分呀。
我现在是0分。
那3分还是系统给的分。 穷呀。
用s:property 能得到startIndex,pageSize的值
但是,pageOffset=startIndex,pageNumber=pageSize
是验证错误pg:pager TagExtraInfo isValid() == false
用startIndex=pageOffset,pageSize=pageNumber
没有报错,但是虽然pager.offset在变,
但是还显示第一页。
[b]问题补充:[/b]
ThinkingInAll 谢谢你的帮助。
我查询了,就是startIndex=pageOffset,pageSize=pageNumber
这个地方有问题。
那个分页是dao层是根据startIndex的值来取分页的内容的。
可是,现在,按下一页pager.offset变了,
但是startIndex没有变,还是0,
就是说分页和逻辑部分没有联系起来。
看了pager的文档,能和逻辑部分联系的就是
export了。
不知道该怎么弄。也许还有别的参数??
help help
[b]问题补充:[/b]
赫赫 谢谢你呀ThinkingInAll
dao 层就是robinn写的那个。
http://www.iteye.com/topic/14657?page=1
action
查询
public String pager() throws Exception{
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Goods.class);
// 查询条件
if (null != getCategory()) {
detachedCriteria.add(Restrictions.in(("category"), getCategory()))
.add(Restrictions.between(("price"), getMinPrice(),getMaxPrice()))
.addOrder(Order.asc("price"));
} else {
detachedCriteria.add(Restrictions.between(("price"), getMinPrice(),getMaxPrice()))
.addOrder(Order.asc("price"));
}
//查询
ps = goodsManager.findpageByCriteria(detachedCriteria, pageSize,startIndex);
previousIndex = ps.getPreviousIndex();
nextIndex = ps.getNextIndex();
startIndex = ps.getStartIndex();
totalCount = ps.getTotalCount();
分页
public String pagerPage() throws Exception{
sessionMap = ActionContext.getContext().getSession();
DetachedCriteria detachedCriteria = (DetachedCriteria)sessionMap.get("detachedCriteriaList");
ps = goodsManager.findpageByCriteria(detachedCriteria, pageSize, startIndex);
totalCount = ps.getTotalCount();
startIndex = ps.getStartIndex();
return SUCCESS;
}
jsp
maxPageItems="7" maxIndexPages="10"
export="pageSize=pageOffset,startIndex=pageNumber" scope="request">
pg:index
pg:first
/pg:first
">[ #<%= pageNumber %> Skip ]
/pg:skip
pg:prev
/pg:prev
pg:pages
/pg:pages
pg:next
/pg:next
">[ Skip #<%= pageNumber %> ]
/pg:skip
pg:last
/pg:last
/pg:index
/pg:pager
谢谢了。
查询url http://localhost:8080/ssh222/pager.action
分页url http://localhost:8080/ssh222/pagerPage.action?pager.offset=7
还有,如果不用pager-taglib做分页,我做上一页,下一页没有问题。我那时是用startIndex来做的。也就说,只要 pageOffset和startIndex 有联系,就没有问题。
还有,这样写pageSize=pageOffset,startIndex=pageNumber不报错。这样写pageOffset=startIndex,pageNumber=pageSize报错
麻烦你了。