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 8958191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:09:19+00:00 2026-06-15T15:09:19+00:00

I am trying to implement lazy loading within my primefaces datatable setup. Currently, this

  • 0

I am trying to implement lazy loading within my primefaces datatable setup. Currently, this is working without the lazy loading implementation, but I get no data in the datatable after implementing the lazy loading. However, I can print my list within my LoadData method to verify that the data is getting loaded into my list, but there seems to be an issue once my LazyModel is returned and the datatable loading is attempted. This could just be something simple that I’m overlooking. Any help is greatly appreciated!

Here is my ScreenshotListProducer class code:

    @ManagedBean
    @RequestScoped
    public class ScreenshotListProducer implements Serializable  {
       private static final long serialVersionUID = 1L;
       @Inject
       private EntityManager em;

       private List<Screenshot> screenshots;

       private LazyDataModel<Screenshot> lazyModel = null;

       private int pageSize = 5;

       public void setPageSize(int pageSize) {
           this.pageSize = pageSize;
       }

       public int getPageSize() {
           return pageSize;
       }

       @Produces
       @Named
       public List<Screenshot> getScreenshots() {
          System.out.println("************* getting screenshots list **************");
          return screenshots;
       }

       @PostConstruct
       public void LoadData() {
            lazyModel = new LazyDataModel<Screenshot>() {
                private static final long serialVersionUID = 1L;

                    @Override
                    public List<Screenshot> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {      
                    int start = first;
                    int end = first + pageSize;

                    try {
                        CriteriaBuilder cb = em.getCriteriaBuilder();
                        CriteriaQuery<Screenshot> criteria = cb.createQuery(Screenshot.class);
                        Root<Screenshot> screenshot = criteria.from(Screenshot.class);
                        criteria.select(screenshot).orderBy(cb.asc(screenshot.get("time")));

                        TypedQuery<Screenshot> s = em.createQuery(criteria);
                        s.setMaxResults(end - start);
                        s.setFirstResult(start);

                        screenshots = s.getResultList();
                        System.out.println("************* lazy screenshot list created **************");
                        for (Screenshot lazylist : screenshots) {
                          System.out.println("id numbers in lazy list: " + lazylist.getId());
                        }
                    } catch (NullPointerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    return screenshots;
                  }
            };
       }

   public LazyDataModel<Screenshot> getLazyModel() {
        return lazyModel;
    }

Here is my Screenshot class:

@Entity
@XmlRootElement
@Table(name="Test2012", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
public class Screenshot implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Column(name = "id", columnDefinition="INT")
    private Long id;

    private Timestamp time;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }   
}

Here is my xhtml code:

    <p:dataTable id="table1" var="scrshot" rowKey="#{scrshot.id}" value="#{screenshotListProducer.lazyModel}" paginator="true" rows="7" paginatorPosition="bottom" 
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="7,20,50,100" widgetVar="dataTable" currentPageReportTemplate="(Number of Records: {totalRecords})"
                 emptyMessage="No screenshot data found with given criteria" lazy="true" scrollable="true" draggableColumns="true" scrollHeight="217" style="width: 100%;">  
          <f:facet name="header">  
            <p:outputPanel>  
                <h:outputText value="Search all fields: "/>  
                <p:inputText id="globalFilter" onkeyup="dataTable.filter()"/>  
            </p:outputPanel>  
          </f:facet> 
          <p:column selectionMode="multiple"/>  
          <p:column id="time" headerText="Time" sortBy="#{scrshot.time}" filterBy="#{scrshot.time}" filterMatchMode="startsWith">  
            <h:outputText value="#{scrshot.time}"/>  
          </p:column>   
          <p:column id="id" headerText="ID" sortBy="#{scrshot.id}" filterBy="#{scrshot.id}" filterOptions="#{scrshot.id}" filterMatchMode="exact">  
            <h:outputText value="#{scrshot.id}"/>  
          </p:column>  
    </p:dataTable>
  • 1 1 Answer
  • 0 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-06-15T15:09:21+00:00Added an answer on June 15, 2026 at 3:09 pm

    Well in the case of lazy loader you will have to set total count of you records like “this.setRowCount(total_records_that_are_there);” in your “load” method. It is necessary for the lazy loader to determine how much pages there will be so that the next and previous buttons on data table can be determined i.e (Enable/disable). Like [0 is start] and [total/rowsize] is the total number of pages however you fetch using the load method with (first and pagezie => skip and limit);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement lazy loading on a blogger blog, but I'm running into
I am trying to implement lazy loading in my app. And I got SDWebImage
I have been trying to implement Lazy Loading of images in Android. I have
Trying to implement a search similar to here .This searches properties based on city,locality,property
While trying to do some tests on lazy loading, to check if i'm understanding
I'm trying to implement a lazy sequence (meaning that the next item is only
Trying to implement simple error handling without adding buku try / except statements to
So I am trying to implement a basic image lazy load feature to speed
I am trying to implement lazy partitioning of an iterator object that yields slices
I'm trying to be lazy and implement the cast operators in the abstract base

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.