Announcement Announcement Module
Collapse
No announcement yet.
Pagination for Key/Value Pair Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pagination for Key/Value Pair

    Hi,

    I'm trying to paginate the content of OneToMany Relationship, so for a given Collection e.g. Map<Object, List<Object>>, contents of key and value pair need to be paged. At the moment, I'm only able to paginate the key using Spring's Pageable Interface. I'm not sure if it is possible to use Pageable in the above scenario.

    if anyone has any suggestions I'd like to hear it.

  • #2
    Hello

    so for a given Collection e.g. Map<Object, List<Object>>
    Why you are such bold style, perhaps exists other way simplier. What requirement you want to solve?

    Lets start by there.

    Comment


    • #3
      Perhaps an analogy will help.

      Consider a database with 2 tables that holds "Questions" and a table that has a "OneToMany" Relationship called "Answers". For any given "Question" there can be in theory hundreds of "Answers". I'd like to paginate the number of Questions retrieved from database and if number "Answers" exceeds a given limit the "Answers" will also be paginated,

      At the moment I'm using Spring's Pageable interface to paginate the contents of first table, I'm looking for a method to paginate both tables.

      I hope this is a little clear.

      Comment


      • #4
        Hello

        Consider a database with 2 tables that holds "Questions" and a table that has a "OneToMany" Relationship called "Answers". For any given "Question" there can be in theory hundreds of "Answers".
        I could do the follow (I am assuming that each Answer is only used how a possible candidate for only one Question)

        Code:
        public class Question{
        
        ...
        private String questionToShow; ans
        private Set<Answer> answers = new HashSet<Answer>();
        
        }
        
        public class Answer{
        
        ...
        private Boolean isTheCorrectAnswer;
        private String answerToShow;
        private Question question
        
        }
        I'd like to paginate the number of Questions retrieved from database
        It has sense, because you would generate many exams, but to avoid repetitions of the questions you would use a random control to select the questions. Lets say you have 250 Questions and the exam only consists in 20 Questions.

        and if number "Answers" exceeds a given limit the "Answers" will also be paginated,
        I would suggest create 10 possibles answers for each question, of course one is only the correct, here I dont see need to add Pagination.

        At the moment I'm using Spring's Pageable interface to paginate the contents of first table, I'm looking for a method to paginate both tables.
        I dont see a reason for the bold part.

        You would have a pagination for the questions and when you do click for any of them you should show its 10 possibles answers and the unique which is valid. Now if you have 50 possibles answers then now has sense use pagination for such answers, but anyway you are in a new page showing a Question with its answer

        Let me know your thoughts

        I hope that I understood your case

        Comment

        Working...
        X