My custom pagination described here has these additional features:
- Selectable page sizes
- Total counts are displayed
- Navigations are not limited to just first, previous, next and last result sets. Mine shows the current and a fixed number of pages before or after the current similarly to how Google does it.
Below is an example of the output:

import com.inventasoft.ui.Pagination;
import com.inventasoft.ui.PageControls;
import com.inventasoft.ui.QueryHelper;
public class YourBean implements QueryHelper{
private Paginationpagination;
private PageControls pageControls = new PageControls();
public void setUp() {
pagination = new Pagination
}
public ListanActionListener() {
pagination.execute(pageControls.getPage(), pageControls.getPageSize());
return pagination.getResults();
}
public Query getCountQuery() {
Object o2 = Component.getInstance("dataEM");
EntityManager em = (EntityManager) o2;
queryEntity.setEjbql("from AResultClass");
queryEntity.setRestrictions(Arrays.asList(RESTRICTIONS));
queryEntity.setOrder(selection.getOrder());
String sqlStr = "select count(*) " + queryEntity.getCountQuery();
Query query = em.createQuery(sqlStr);
return query;
}
public Query getSelectQuery(int start, int pageSize) {
Object o2 = Component.getInstance("dataEM");
EntityManager em = (EntityManager) o2;
String selectQuery = queryEntity.getQuery();
Query query = em.createQuery(selectQuery);
query.setFirstResult(start);
query.setMaxResults(pageSize);
return query;
}
}
Very good. Interested to see the entire utility if you dont mind ?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSee my September's blog for a simpler way to do this.
ReplyDelete