-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: ..stuts pagination
PostPosted: Sun Nov 13, 2005 1:16 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 11:51 pm
Posts: 45
..can someone help me to do a pagination with stuts framework combine with hibernate...thanks a lot.


Top
 Profile  
 
 Post subject: Re: ..stuts pagination
PostPosted: Sun Nov 13, 2005 5:28 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
jack182 wrote:
..can someone help me to do a pagination with stuts framework combine with hibernate...thanks a lot.


Hi...
From the point of view of Hibernate, you may paginate the data in this way:
suppose you must query for the first page of data, composed of 30 objects.
You may do something of :
Code:
Query query = currentSession.createQuery("from User u");
query.setFirstResult(0);
query.setMaxResults(NUMBER_OF_ELEMENTS_PER_PAGE);
List users = query.list();

In this case we are supposing the first page is composed of 10 elements.
Now we wish to load the second page (of 10 elemens too).
Code:
Query query = currentSession.createQuery("from User u");
query.setFirstResult(10);
query.setMaxResults(NUMBER_OF_ELEMENTS_PER_PAGE);
List users = query.list();


...and so on.


By(te)

-

Pleas don't forget to credit ,-)


Top
 Profile  
 
 Post subject: Re: ..stuts pagination
PostPosted: Sun Nov 13, 2005 5:35 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
Sorry... I made some error!


Quote:
suppose you must query for the first page of data, composed of NUMBER_OF_ELEMENTS_PER_PAGE objects.


...

Quote:
In this case we are supposing the first page is composed of NUMBER_OF_ELEMENTS_PER_PAGE elements.
Now we wish to load the second page (of NUMBER_OF_ELEMENTS_PER_PAGE elemens too).


...

Also see this: http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-executing-pagination

Excuse me for the confusion!

By(te)
-

Pleas don't forget to credit ,-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 13, 2005 5:53 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
Code:
/**
  page must be a value starting from 0
*/
public List getUsersPerPage(int page)
{
     Query query = currentSession.createQuery("from User u");
     query.setFirstResult(page * NUMBER_OF_ELEMENTS_PER_PAGE);
     query.setMaxResults(NUMBER_OF_ELEMENTS_PER_PAGE);
     return query.List();
}


By(te)!!!

-

Please don't forget to credit ,-)[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.