Primefaces Push and Tomcat 8 don't work

UI Components for JSF
Post Reply
castor82
Posts: 23
Joined: 22 Jan 2014, 17:42

30 Oct 2016, 21:14

I am working with Primefaces Push with Apache Tomcat 8, but it doesn't work and I have the following error:

Code: Select all

 WARNING [http-nio-8080-exec-14] com.sun.faces.lifecycle.InvokeApplicationPhase.execute /book_add.xhtml @25,81 actionListener="#{bookBean.addBook}": java.lang.NullPointerException  javax.el.ELException: /book_add.xhtml @25,81 actionListener="#{bookBean.addBook}": java.lang.NullPointerException
my code is :

NotifyPush.java

Code: Select all

@PushEndpoint("/notify")
  public class NotifyPush {

  @OnMessage(encoders = {JSONEncoder.class})
  public FacesMessage onMessage(FacesMessage message) {
    return message;
  }
}
BookBean.java

Code: Select all

@ManagedBean(name = "bookBean")
@SessionScoped
public class BookBean implements Serializable{

private Book book = new Book();
private static List<Book> lstBook = new ArrayList();

public void addBook(ActionEvent event) {
    this.lstBook.add(book);
    notifyPUSH();
}

public void notifyPUSH() {
    String summary = "Next Element";
    String detail = "Add to List";
    String CHANNEL = "/notify";

    EventBus eventBus = EventBusFactory.getDefault().eventBus();
    eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml3(summary), StringEscapeUtils.escapeHtml3(detail)));
}

//getters and setters
}
web.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee  http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>  
<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>faces/book_list.xhtml</welcome-file>
</welcome-file-list>
</web-app>
book_add.xhtml

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>  
        <h2>ADD BOOK</h2>
        <p:panelGrid columns="3">
            <p:outputLabel value="Code :" />
            <p:inputText value="#{bookBean.book.code}"/>
            <h:outputText value="&#160;&#160;&#160;"/>

            <p:outputLabel value="Title : " />
            <p:inputText value="#{bookBean.book.name}"/>            
            <h:outputText value="&#160;&#160;&#160;"/>

            <p:outputLabel value="Num. Pages : " />
            <p:inputText value="#{bookBean.book.numPages}"/>   
            <h:outputText value="&#160;&#160;&#160;"/>
        </p:panelGrid>
        <p:commandButton value="Add" actionListener="#{bookBean.addBook}" />
    </h:form>
</h:body>
But I work Primefaces Push with GlassFish and it works fine. I am working with primefaces 5.3,atmosphere-runtime-2.4.5.jar,slf4j-api-1.7.21.jar and commons-lang3-3.4.jar.

Thanks for all
PrimeFaces: primefaces-4.0.jar, JSF 2.2.0, Faceletes
Spring 3.2
Hibernate 4.1
Netbeans 7.4
Tomcat 7.0.47
Windows 7 SP1

djanthony93
Posts: 7
Joined: 18 Nov 2016, 00:29

18 Nov 2016, 02:14

Same issues here.

I fixed by using the Inject annotation, take the showcase count example, my CounterView class looks like this:

Code: Select all

@ManagedBean
@ApplicationScoped
public class CounterView implements Serializable{

    private volatile int count;

    @Inject
    private EventBus eventBus;

    public CounterView(){
        eventBus = EventBusFactory.getDefault().eventBus();
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void increment() {
        count++;

        eventBus.publish("/counter", String.valueOf(count));
    }
}
I don't if that's normal or not, but when I click the Click button (see the example), the page is refreshed. By the way I'm using Primefaces 6.0 with Atmosphere 2.4.8

romanze7
Posts: 2
Joined: 10 Mar 2017, 10:37

10 Mar 2017, 11:08

Thx for that fixed.
goldenslot

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests