相信对JSF有一定了解的童鞋,都知道怎么用dataGrid显示数据,一般情况我都是用的都是客户端分页,闲来无事按照例子写了个服务器端分页,话不多说,贴代码:
@Inject(value = "employeeSpringService") private IEmployeeService es; @Bind(id = "grid", attribute = "value") private GridDataProvider dataProvider = new CachedPagedDataProviderAdapter( new CachedPagedDataProvider() { @Override public Object getData(int start, int limit) { return es.limitQuery(start, limit).toArray(); } @Override public int getTotalCount() { List list=es.getTotal(); return ((Long)list.get(0)).intValue(); } });
?
public List<Employee> limitQuery(int start,int limit) { logger.debug("finding the queried Employee instances"); try { DetachedCriteria dc=DetachedCriteria.forClass(Employee.class); List<Employee> results = (List<Employee>) getHibernateTemplate().findByCriteria(dc, start, limit); logger.debug("find queried successful, result size: " + results.size()); return results; } catch (RuntimeException re) { logger.error("find queried failed", re); throw re; } } public List getTotal() { logger.debug("finding the queried Employee instances"); try { List results =getHibernateTemplate().find("select count(*) FROM Employee"); logger.debug("find queried successful, result size: " + results.size()); return results; } catch (RuntimeException re) { logger.error("find queried failed", re); throw re; } }
?主要就是getHibernateTemplate().findByCriteria()方法。。。