Reputation: 9935
PrimeFaces LazyDataModel
worked before adding OmniFaces jar into pom.xml.
It invokes load()
method of LazyDataModel
.
LazyPostDataModel.java
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
}
}
I just add the following dependency into pom.xml for OmniFaces. It does not invoke load()
method .
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
post.xhtml
<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>
ManagePostActionBean.java
@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);
}
}
my environment is
JSF 2.2
Primefaces 5.0
JDK 1.7
apache-tomee-webprofile-1.7.3 (TomEE)
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mutu</groupId>
<artifactId>spring-primefaces</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>green-cool</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
Upvotes: 1
Views: 769
Reputation: 1108782
You're using TomEE 1.x, which ships with JSF 2.1 (Apache MyFaces).
OmniFaces 2.2 requires JSF 2.2.
You have 2 options:
Downgrade to OmniFaces 2.1. Even though OmniFaces 2.x officially requires JSF 2.2, OmniFaces versions 2.0 and 2.1 do not have deploy time JSF 2.2 dependencies. OmniFaces version 2.2 was with <o:viewAction>
tag the first version to require JSF 2.2 during deploy time.
Upgrade to TomEE 7.x, the first version to implement Java EE 7 and thus inherently JSF 2.2. It's currently only available as M1 release. Final release is expected within months.
Upvotes: 1