---
title: "关于rich:datascroller当前页码的保存与恢复"
author: "happylo"
date: "2009-02-17T15:00:00Z"
tags: []
slug: "rich-datascroller"
draft: false
lastmod: "2009-02-17T15:00:00Z"
id: 334159
url: "https://happydev.iteye.com/blog/334159"
---

\[原创于：[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">
```