Guest User

Untitled

a guest
Oct 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <p:dataTable value="#{productListMg.productsListLazy}"
  2. lazy="true"
  3. paginatorPosition="top"
  4. paginator="true"
  5. paginatorAlwaysVisible="false"
  6. rows="12"
  7. var="prd" rowIndexVar="rowIndex" id="productTb"
  8. styleClass="horizontal-line-table inline-button">
  9.  
  10. @ManagedBean
  11. @ViewScoped
  12. public class ProductListMg {
  13. public ProductListMg()
  14. {
  15. productsListLazy=new NamingBaseLazyModel(Product.class);
  16. }
  17. }
  18.  
  19. @Override
  20. public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
  21. return NamingDl.getInstance().loadNamingObjectsLazy(cls, first, pageSize, sortField, sortOrder, filters);
  22. }
  23.  
  24. @Override
  25. public int getRowCount() {
  26. return NamingDl.getInstance().getNamingLazyObjectSize(cls);
  27. }
  28.  
  29. public int getNamingLazyObjectSize(Class cls) {
  30. Session session = getSessionFactory().openSession();
  31. int rc = 0;
  32. try {
  33. Criteria crit = session.createCriteria(cls);
  34.  
  35. crit.setProjection(Projections.rowCount());
  36. List l=crit.list();
  37. if (l!=null && l.size()>0) {
  38. Long rc2 = (Long)l.get(0);
  39. if (rc2 != null)
  40. rc = rc2.intValue();
  41. return rc;
  42. }
  43. } catch (Exception ex) {
  44. ex.printStackTrace();
  45. } finally {
  46. session.close();
  47. }
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment