PrimeFaces LazyDataModel
在将OmniFaces jar添加到pom.xml之前工作。
它调用load()
的{{1}}方法。
LazyPostDataModel.java
LazyDataModel
我只是将以下依赖项添加到OmniFaces的pom.xml中。它不会调用public class LazyPostDataModel extends LazyDataModel<Post> {
private PostService postService;
private PostCriteria postCriteria;
public LazyPostDataModel(PostService postService, PostCriteria postCriteria) {
this.postCriteria = postCriteria;
this.postService = postService;
}
@Override
public List<Post> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) {
//other process
}
}
方法。
load()
post.xhtml
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
ManagePostActionBean.java
<h:form id="postTableForm">
<p:inputText value="#{ManagePostActionBean.postCriteria.name}"/>
<p:commandButton value="Search" action="#{ManagePostActionBean.search}" update="postTable"/>
<p:outputPanel id="listPanel">
<p:dataTable var="post" value="#{ManagePostActionBean.postDataModel}" id="postTable"
paginator="true" style="width:100%;" lazy="true"
rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10, 20, 30, 40, 50, 100" rowIndexVar="index">
<p:column headerText="No" style="width:50px;">
<h:outputText value="#{index + 1}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{post.name}" />
</p:column>
<p:column headerText="Description">
<h:outputText value="#{post.description}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
我的环境是
@Named(value = "ManagePostActionBean")
@ViewScoped
public class ManagePostActionBean {
@Inject
private PostService postService;
private LazyDataModel<Post> postDataModel;
private PostCriteria postCriteria;
public void onLoad() {
System.out.println("ManagePostActionBean Init....");
postCriteria = new PostCriteria();
postDataModel = new LazyPostDataModel(postService, postCriteria);
}
public LazyDataModel<Post> getPostDataModel() {
return postDataModel;
}
public PostCriteria getPostCriteria() {
return postCriteria;
}
public void setPostCriteria(PostCriteria postCriteria) {
this.postCriteria = postCriteria;
}
public void search() {
resetPagination();
postDataModel = new LazyPostDataModel(postService, postCriteria);
}
}
的pom.xml
JSF 2.2
Primefaces 5.0
JDK 1.7
apache-tomee-webprofile-1.7.3 (TomEE)
答案 0 :(得分:1)
您使用的是TomEE 1.x,它随JSF 2.1(Apache MyFaces)一起提供。
OmniFaces 2.2 requires JSF 2.2。
您有两个选择:
降级为OmniFaces 2.1。即使OmniFaces 2.x正式要求JSF 2.2,OmniFaces版本2.0和2.1也没有部署时间JSF 2.2依赖项。 OmniFaces 2.2版带有<o:viewAction>
标记在部署期间需要JSF 2.2的第一个版本。
升级到TomEE 7.x,这是实现Java EE 7的第一个版本,因此也就是JSF 2.2。 M1版本目前只有available。预计最终版本将在几个月内发布。