Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:28:28+00:00 2026-05-16T08:28:28+00:00

Do you know this feeling when every code you write works immedietly and you

  • 0

Do you know this feeling when every code you write works immedietly and you underrun your schedule 😛 It’s like ‘oh yeah now I have time to make it perfect’. That’s where I am at the moment^^

So I implemented a repeater with JSF (ui:repeat) and I thought about a paging for all the entities. Is there maybe an easy way to do that? What are the points I have to think about?

Would be nice if someone gives me some help. My googleskills haven’t helped me so far 😛

Cheers…

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:28:29+00:00Added an answer on May 16, 2026 at 8:28 am

    Here is a simple example that should give you the idea on how to implement this.

    RepeatPaginator:

    public class RepeatPaginator {
    
        private static final int DEFAULT_RECORDS_NUMBER = 2;
        private static final int DEFAULT_PAGE_INDEX = 1;
    
        private int records;
        private int recordsTotal;
        private int pageIndex;
        private int pages;
        private List<?> origModel;
        private List<?> model;
    
        public RepeatPaginator(List<?> model) {
            this.origModel = model;
            this.records = DEFAULT_RECORDS_NUMBER;
            this.pageIndex = DEFAULT_PAGE_INDEX;        
            this.recordsTotal = model.size();
    
            if (records > 0) {
                pages = records <= 0 ? 1 : recordsTotal / records;
    
                if (recordsTotal % records > 0) {
                    pages++;
                }
    
                if (pages == 0) {
                    pages = 1;
                }
            } else {
                records = 1;
                pages = 1;
            }
    
            updateModel();
        }
    
        public void updateModel() {
            int fromIndex = getFirst();
            int toIndex = getFirst() + records;
    
            if(toIndex > this.recordsTotal) {
                toIndex = this.recordsTotal;
            }
    
            this.model = origModel.subList(fromIndex, toIndex);
        }
    
        public void next() {
            if(this.pageIndex < pages) {
                this.pageIndex++;
            }
    
            updateModel();
        }
    
        public void prev() {
            if(this.pageIndex > 1) {
                this.pageIndex--;
            }
    
            updateModel();
        }   
    
        public int getRecords() {
            return records;
        }
    
        public int getRecordsTotal() {
            return recordsTotal;
        }
    
        public int getPageIndex() {
            return pageIndex;
        }
    
        public int getPages() {
            return pages;
        }
    
        public int getFirst() {
            return (pageIndex * records) - records;
        }
    
        public List<?> getModel() {
            return model;
        }
    
        public void setPageIndex(int pageIndex) {
            this.pageIndex = pageIndex;
        }
    
    }
    

    Bean:

    public class TestBean {
    
        private List<String> list;
        private RepeatPaginator paginator;
    
        @PostConstruct
        public void init() {
            this.list = new ArrayList<String>();
            this.list.add("Item 1");
            this.list.add("Item 2");
            this.list.add("Item 3");
            this.list.add("Item 4");
            this.list.add("Item 5");
            this.list.add("Item 6");
            this.list.add("Item 7");
            this.list.add("Item 8");
            this.list.add("Item 9");
            this.list.add("Item 10");
            this.list.add("Item 11");
            paginator = new RepeatPaginator(this.list);
        }
    
        public RepeatPaginator getPaginator() {
            return paginator;
        }
    
    }
    

    XHTML:

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        template="/WEB-INF/template/default.xhtml">
    
    <ui:define name="content">
        <h:form>
            <ui:repeat value="#{testBean.paginator.model}" var="listItem">
                <div>
                    <h:outputText value="#{listItem}"/>
                </div>
            </ui:repeat>
            <h:commandButton value="&lt; prev" action="#{testBean.paginator.prev}"/>
            <h:outputText value="#{testBean.paginator.pageIndex} / #{testBean.paginator.pages}"/>
            <h:commandButton value="next &gt;" action="#{testBean.paginator.next}"/>
            <h:inputHidden value="#{testBean.paginator.pageIndex}"/>
        </h:form>
    </ui:define>
    </ui:composition>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very bad feeling about using lock in my code but now
I know this is an old question, but I have spend any hours on
I have been looking for a solution to this problem for a while now
You know that particular part of your code that is essential for the project
I have a data.frame df and I want that every row in this df
I have a feeling this is a repost but I can't seem to find
I think I have something like programmer's OCD. I like my code to be
Know this might be rather basic, but I been trying to figure out how
i know this is a stupid question but i d'ont know how to do
I know this is a frequently asked question and I havent got a clear

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.