1

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>
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131
  • Did you manually upgrade JSF from 2.1 to 2.2 in TomEE? If so, how exactly? TomEE 1.x is by default not JSF 2.2 but JSF 2.1 and then you should use OmniFaces 1.x instead of 2.x, or migrate server to TomEE 7.x. – BalusC Feb 16 '16 at 10:01
  • @BalusC I just add com.sun.face 2.2 in pom.xml manually. it is not OK? – Zaw Than oo Feb 16 '16 at 10:11
  • No ... `provided` means "Target runtime (the appserver) already provides it". Moreover, TomEE 1.x provides Apache MyFaces (org.apache.myfaces), not Oracle Mojarra (com.sun.faces). I'm only surprised that you didn't see an exception during deploy as in this closely related question: http://stackoverflow.com/q/35226794 – BalusC Feb 16 '16 at 10:11
  • And you say you use PF 5.3 but the pom show 5.0... Please correct all... – Kukeltje Feb 16 '16 at 10:14
  • @BalusC I need to upgrade JSF 2.2 on Tomee? If so, I will googling for that. After that, I will feed back u later – Zaw Than oo Feb 16 '16 at 10:15
  • I posted an answer. In all honesty, I have to say that it's kind of strange to see someone using Spring on a Java EE server. I can understand why one would use Spring on a barebones Tomcat servletcontainer (as you can't install EJB on it), but TomEE already ships EJB/JTA/JPA/CDI/JAX-RS/etc out the box so there's no real need for Spring. By the way, your JSTL dependency must be marked `provided`. – BalusC Feb 16 '16 at 10:20
  • @BalusC, thank for your help. Actually I am thinking to choose the way. JSF 2.2 + Spring + Tomcat 7. But I get '@PostConstruct calling multiple time in ViewScope bean` error. Some reference suggest to use CDI for that case. That's why I choose this way(as my post). I will choose option 1 or 2 of your answer. But, I need to test both. – Zaw Than oo Feb 16 '16 at 10:31

1 Answers1

1

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:

  1. 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.

  2. 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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555