re: 【第三版】RichFaces中使用datatable和datascroller进行分页(使用数据库分页,改良版)(含源码)(JSF 1.2,RichFaces 3.2.1GA)
2010-03-16 01:34 |
public class UsePage extends PageListBaseBean{
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
IUserDAO userDAO = (UserDAO)context.getBean("userDao");
//private IUserService userService;
private User user; // 当前对象
private String operation; // 操作标识符
public UsePage() {
datas = new ArrayList<User>();
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void setDatas(List<User> datas) {
this.datas = datas;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
/**
* 分页查询记录
*/
public String getUserByPage(){
defaultDataModel = this.getDefaultDataModel();
System.out.println("in getUserByPage Now!!");
return "listPage";
}
@Override
public PagedListDataModel getDefaultDataModel() {
// TODO Auto-generated method stub
if ( defaultDataModel == null ) {
defaultDataModel = new PagedListDataModel(pageSize)
{
public DataPage fetchPage(int startRow, int pageSize)
{
System.out.println("PagedListDataModel!!");
Map<String,Integer> pageMap = new HashMap<String,Integer>();
pageMap.put("start",startRow);
pageMap.put("end",pageSize);
//IUserDAO userDAO = (UserDAO)context.getBean("userDao");
List list= userDAO.getUserByPage(pageMap);
for(int i=0;i<list.size();i++){
User user = new User();
user = (User) list.get(i);
System.out.print(user.getId());
System.out.print(user.getName());
System.out.print(user.getSex());
System.out.println(user.getBirthday());
}
int count = userDAO.getCount();
System.out.println("count="+count);
return new DataPage(count, startRow, list);
}
};
}
return defaultDataModel;}
}其他代码都是一样的,就是这个地方不一样!!
回复 更多评论