O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – loading the DataTable data leisurely

Let us see how to use DataTable with the lazy loading feature.

  1. Create a DataTable component with the LazyDataModel binding and set the lazy attribute to true, as shown in the following code:
    <p:dataTable id="usersTbl" var="user" value="#{adminController.lazyUserModel}" paginator="true" rows="10" lazy="true"> 
      <p:column headerText="Id" sortBy="#{user.id}" >  
        <h:outputText value="#{user.id}" />  
      </p:column>  
    
      <p:column headerText="FirstName" filterBy="#{user.firstName}" sortBy="#{user.firstName}">  
        <h:outputText value="#{user.firstName}" />  
      </p:column>  
    </p:dataTable>
  2. Implement LazyUserModel by extending LazyDataModel to load data lazily:
    import org.primefaces.model.LazyDataModel; import org.primefaces.model.SortOrder; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required