这是关于PrimeFaces延迟加载
<h:head>
<title>data table with pagination</title>
</h:head>
<h:body>
<h3>datatable with pagination</h3>
<p:dataTable var="lazemp" value="#{lazy.lazy1}" paginator="true" rows="8"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,8,11" lazy="true">
<p:column headerText="ID">
<h:outputText value="#{lazemp.id}"/>
</p:column>
<p:column headerText="NAME">
<h:outputText value="#{lazemp.name}"/>
</p:column>
<p:column headerText="SPECIFICATION">
<h:outputText value="#{lazemp.specification}"/>
</p:column>
</p:dataTable>
这里必须从这个java文件中获取数据。
@ManagedBean(name = "lazy")
@RequestScoped
public class Lazyload {
private LazyDataModel<Employee> lazy1;
public LazyDataModel<Employee> getLazy1() {
return lazy1;
}
public void setLazy(LazyDataModel<Employee> lazy1) {
this.lazy1 = lazy1;
}
@PostConstruct
public void init() {
lazy1 = new LazyDataModel<Employee>() {
public ArrayList<Employee> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String, String> filters) {
Employee e1 = new Employee();
e1.setId(1);
e1.setName("solo");
e1.setSpecification("java");
Employee e2 = new Employee();
e2.setId(2);
e2.setName("shamin");
e2.setSpecification("spring");
Employee e3 = new Employee();
e3.setId(3);
e3.setName("pranesh");
e3.setSpecification("php");
Employee e4 = new Employee();
e4.setId(4);
e4.setName("ravi");
e4.setSpecification("pearl");
Employee e5 = new Employee();
e5.setId(5);
e5.setName("bopara");
e5.setSpecification("onrails");
Employee e6 = new Employee();
e6.setId(6);
e6.setName("anish");
e6.setSpecification("unix");
Employee e7 = new Employee();
e7.setId(7);
e7.setName("darwin");
e7.setSpecification("c");
Employee e8 = new Employee();
e8.setId(8);
e8.setName("gangadaran");
e8.setSpecification("hibenate");
Employee e9 = new Employee();
e9.setId(9);
e9.setName("cyrus");
e9.setSpecification("python");
Employee e10 = new Employee();
e10.setId(10);
e10.setName("senthil");
e10.setSpecification("testing");
Employee e11 = new Employee();
e11.setId(11);
e11.setName("balaji");
e11.setSpecification("dijango");
Employee e12 = new Employee();
e12.setId(12);
e12.setName("kannan");
e12.setSpecification("visualc");
Employee e13 = new Employee();
e13.setId(13);
e13.setName("beljo");
e13.setSpecification("angular js");
Employee e14 = new Employee();
e14.setId(14);
e14.setName("ananthu");
e14.setSpecification("css");
Employee e15 = new Employee();
e15.setId(15);
e15.setName("kuttan");
e15.setSpecification("c++");
Employee e16 = new Employee();
e16.setId(16);
e16.setName("mani");
e16.setSpecification("cobol");
Employee e17 = new Employee();
e17.setId(17);
e17.setName("sangakara");
e17.setSpecification("ceylon");
Employee e18 = new Employee();
e18.setId(3);
e18.setName("solop");
e18.setSpecification("scala");
Employee e19 = new Employee();
e19.setId(19);
e19.setName("bryant");
e19.setSpecification("java");
Employee e20 = new Employee();
e20.setId(20);
e20.setName("lynn");
e20.setSpecification(".net");
Employee e21 = new Employee();
e21.setId(21);
e21.setName("shen");
e21.setSpecification("angularjs");
Employee e22 = new Employee();
e22.setId(22);
e22.setName("jacob");
e22.setSpecification("ajax");
Employee e23 = new Employee();
e23.setId(3);
e23.setName("paul");
e23.setSpecification("gwt");
ArrayList<Employee> lazyemp = new ArrayList<Employee>();
lazyemp.add(e1);
lazyemp.add(e2);
lazyemp.add(e3);
lazyemp.add(e4);
lazyemp.add(e5);
lazyemp.add(e6);
lazyemp.add(e7);
lazyemp.add(e8);
lazyemp.add(e9);
lazyemp.add(e10);
lazyemp.add(e11);
lazyemp.add(e12);
lazyemp.add(e13);
lazyemp.add(e14);
lazyemp.add(e15);
lazyemp.add(e16);
lazyemp.add(e17);
lazyemp.add(e18);
lazyemp.add(e19);
lazyemp.add(e20);
lazyemp.add(e21);
lazyemp.add(e22);
lazyemp.add(e23);
return lazyemp;
}
};
lazy1.setRowCount(15);
}
}
在运行时只获取没有数据的列文本,显示没有任何记录存在,我被任何帮助都会受到赞赏