2

I'm developing a web application using MVC architectural pattern.

  • Struts2 (version 2.3.24) is used for the Business Logic and Presentation Layer
  • Spring (version 4.1.0) is the dependency injection engine
  • Hibernate (version 3.6.10) is used for the Data Layer.

I have to create a PaginationFactory class that I can dynamically use for the various section of the application. I've several examples on google and StackOverflow... But mostly old stuff like this question.

Any ideas on how implement this function with using something more modern? Maybe with JQuery and Ajax as support?

Community
  • 1
  • 1
IlGala
  • 3,331
  • 4
  • 35
  • 49
  • I was looking at the [Criteria API](https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html) documentation... Can be a good start? – IlGala Jul 06 '15 at 20:31
  • Are you at the beginning, or the application is already developed ? Is this stack a company standard ? +1 for 2.3.24 :) but as it is now, this seems a bit too broad... – Andrea Ligios Jul 07 '15 at 07:32
  • No, i'm at the beginning, it's a medical software, so there are many typological tables, documents etc... that requires a good pagination, thanks in advance, if you need more info tell me! – IlGala Jul 07 '15 at 09:22
  • What exactly you are asking? Link to some paginator? It is OT. How to implement pagination your self? It is too broad. – Aleksandr M Jul 07 '15 at 09:30
  • Well I have to optimize the layout of the results (in a year we talk about 3-400k documents). What I look for is a good paging system that is compatible with the technologies used since what i've found in the internet it's kinda old, or guidelines in order to initially create the bare essentials – IlGala Jul 07 '15 at 09:34
  • 1
    @IlGala if you are at the beginning then, I suggest you to go full Java EE (*apart from Struts2 over JSF2...*) and use Struts2 + [CDI](http://stackoverflow.com/questions/26733141/load-and-cache-application-scoped-data-with-singleton-and-stateless) (for DI, instead of Spring) + JPA 2 (with Hibernate as implementation). Then read [this](http://stackoverflow.com/questions/5349264/total-row-count-for-pagination-using-jpa-criteria-api) along with all the answers to achieve the pagination in JPA. – Andrea Ligios Jul 07 '15 at 09:52

1 Answers1

0

I suggest for you to use Spring Data Jpa, it's already have implemented pagination.

Your repository will look like this:

public interface MedicamentRepository extends JpaRepository<Medicament, Integer> {}

You can extend, as example, PagingAndSortingRepository interface, if you don't need some of methods that JpaRepository provides.

public class SomeClass{

@Autowired
public MedicamentRepository medicamentRepo; 

 public void someMethod(){
//in spring data jpa, page count starts from 0; 
 PageRequest pageRequest = new PageRequest(pageNumber, 
pageSize); //also have sorting

org.springframework.data.domain.Page<Medicament> page = medicamentRepo.findAll(pageRequest);

    }
}

you can read more here

Yaroslav
  • 111
  • 4
  • 3