ITeye博客

关于rich:datascroller当前页码的保存与恢复

happylo · 2009-02-17 15:00 · Seam/JSF/EJB3相关杂项 · Markdown

[原创于:http://happydev.iteye.com]

 

在使用rich:datascroller配合rich:dataTable使用过程中,经常会有这样的使用场景:要保存当前页码,然后跳转到一个其它的页面,当返回时又要恢复保存的页码。

本文就如何实现这样的一个应用场景进行一下说明:

 

创建一个保存当前页面代码的组件

@Name("pageHolder")
@Scope(ScopeType.CONVERSATION)
public class PageHolder {
	private int currPage;

	@Begin
	@Create
	public void creat(){
		System.out.print("test");
	}
	
	public void lsn(DataScrollerEvent event) {
		// 当前点击的页数
		String pageCount = event.getNewScrolVal().toString();
		this.currPage=Integer.parseInt(pageCount);
	}
	
	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public int getCurrPage() {
		return currPage;
	}
}

  

 

页面代码:

 

            <rich:datascroller pageIndexVar="currPage" scrollerListener="#{pageHolder.lsn}" page="#{pageHolder.currPage}" align="left" for="entGeneralAccountList" maxPages="20" rendered="#{entGeneralAccountList.rowCount > 20}"/>
            <rich:spacer height="30" rendered="#{entGeneralAccountList.rowCount > 20}"/>
            <rich:dataTable width="100%" id="entGeneralAccountList" rows="20" columnClasses="col" value="#{entGeneralAccountList}" var="entGeneralAccount">

评论(6)

  1. #6 楼 · yuanliyin · 2010-11-12 12:42

    测试了下这样会存在问题,直接点击上一页,下一页等时候,传入u的参数是first、 fastrewind、fastforward、last,Integer.parseInt(pageCount);就会出现问题了,所以其实不用这么麻烦,直接缓存currPage就好了,不用监听

  2. #5 楼 · rainliu · 2009-07-29 13:52

    写得不错,这几天正在想怎样这类问题,刚刚找到您的文章,受益啦。。谢谢

  3. #4 楼 · caoxiaohui · 2009-03-30 14:50

    请教一下,DataScrollerEvent这个是什么??

  4. #3 楼 · happylo · 2009-03-03 11:45

    joysoftfan writes:

    请教一个seam分层的问题,将action和ui分开能分吗?

    本来就分得很开啊。

  5. #2 楼 · joysoftfan · 2009-03-02 23:45

    请教一个seam分层的问题,将action和ui分开能分吗?

  6. #1 楼 · sunjia2003112407 · 2009-02-19 16:24

    恩,写的很好,谢谢了。如果可以加分的话一定给你很多很多的........分.

评论功能维护中,当前仅展示历史评论。