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
Code: Select all
<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
Code: Select all
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);
}
}