Board index JavaServer Faces General PageNumber problem with Lazy loading in datatable

PageNumber problem with Lazy loading in datatable

Components, Ajax Framework, Utilities and More.


Posts: 5

Hello;

I am going on to use datatable. First I succeded to show the first page with related data sets. But when I click the next button coming with datatable, first's value in below method is always 0.

lazyModel = new LazyDataModel<AddressAwareLogLine>(this.datasetSize) {
@Override
public List<AddressAwareLogLine> fetchLazyData(int first, int pageSize)
{ ... }
};

I printed first and pagesize parameters at the beginning of the fetchLazyData method, I t always prints first as zero. So, obviously, I get first page all the time whatsoever I do. Obviously, I wait (clicked page no - 1) * pageSize value for first value. For ex; pageSize = 100 and I am in first page when I clicked next
I hope first's value is 100 and pageSize is 100 for the fetchLazyData method invocation. But always same values as 0, 100 for the method paramters...

I add the codes related with my project. Any help is appreciated? Thanks


search.xhtml
<html 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"
      xmlns:a4j="http://richfaces.org/a4j"first
      xmlns:rich="http://richfaces.org/rich"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="/templates/endertpl/template.xhtml">

        <ui:define name="breadcrumb">
            <h:outputLink
                value="${facesContext.externalContext.requestContextPath}/index.xhtml">Home</h:outputLink>
        </ui:define>
        <ui:define name="htmlHeadPart">
            <p:resources />
        </ui:define>

        <ui:define name="body">
            <h:form >
                <p:dataTable var="car" value="#{tableBean.lazyModel}" paginator="true" rows="10"
                             dynamic="true" lazy="true" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                             width="300px">
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Model" />
                        </f:facet>
                        <h:outputText value="#{car.model}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Year" />
                        </f:facet>
                        <h:outputText value="#{car.year}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Manufacturer" />
                        </f:facet>
                        <h:outputText value="#{car.manufacturer}" />
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Color" />
                        </f:facet>
                        <h:outputText value="#{car.color}" />
                    </p:column>
                </p:dataTable>

            </h:form>

        </ui:define>

    </ui:composition>
</html>



TableBean


import java.util.ArrayList;
import java.util.List;
import org.primefaces.model.LazyDataModel;

public class TableBean {

   

   private LazyDataModel<Car> lazyModel;

   public TableBean() {
      /**
      * Test with one hundred million records.
      * In a real application use an sql Count query to get the row count.
      */
      lazyModel = new LazyDataModel<Car>(100000000) {

         /**
          * Dummy implementation of loading a certain segment of data.
          * In a real applicaiton, this method should access db and do a limit based query
          */
         @Override
         public List<Car> fetchLazyData(int first, int pageSize) {
            System.out.println("first value = " + first);
                                System.out.println("page size value = " + pageSize);
            List<Car> lazyCars = new ArrayList<Car>();
            populateLazyRandomCars(lazyCars, pageSize, first);

            return lazyCars;
         }
      };
   }

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

   private void populateLazyRandomCars(List<Car> list, int size, int first) {
      for(int i = 0 ; i < size ; i++) {
         int offset = i + first;
         list.add(new Car("Model_" + offset, getRandomYear(), "Brand_" + offset, "Color_" + offset));
      }
   }

   private int getRandomYear() {
      return (int) (Math.random() * 50 + 1960);
   }
}
            

--

ilkay POLAT

Software Engineer


Posts: 5

I have looked at the source code site for primefaces at http://code.google.com/p/primefaces. I have tested lazy loading with these codes. And I faced same result that I faced. I do not know if it comes because of my configurations or not. I assigned the managed bean's scope as session, even I tried application scope whether the problems is from scope or not. I just add the println before the fetchLazyData method as shown below.
 public List<Car> fetchLazyData(int first, int pageSize) {
      System.out.println("first : " + first);
      System.out.println("Pagesize : " + pageSize);
      ...........
}


But whatsoever I do, same result as shown below when entering the fetchLazyData method.

...
first : 0
Pagesize : 10

But, I wait first's values as 0, 10, 20 etc.

Is there anybody used datatable with lazy loading facility, and get succeeded? Thanks again
--

ilkay POLAT

Software Engineer


Posts: 5

I have recreated all the things for lazy loading feature of data table in primefaces and used eclipse. I succeded lazy loading data table in this time :) . I think problem is related with my deployment desciptor.

Because; I ran the project in eclipse and nothing is added to server log except my logs. But in my going on project which is in netbeans IDE , there is always 2 line when I click the page navigation buttons. These logs are given below:
---
First : 0
PageSize : 10
Jun 24, 2010 12:57:44 PM org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider newInstance
INFO: Creating instance of org.primefaces.resource.ResourceHolderImpl

----

As a conclusion, I understood that it is my fault to test datatable in primefaces. Now, I am searching why this two lines are coming may be fault is from this reason :?:
--

ilkay POLAT

Software Engineer


Posts: 14905
Location: Cybertron

No worries the logs are not errors but you might want to change your log levels not to get them anymore.
PrimeFaces Lead


Return to General