Primefaces: EventBusFactory.getDefault () returns null

5

I am developing an application with Primefaces that uses the pub / sub model provided by this framework.

Technology stack:

  • tomcat 8
  • java 8
  • primefaces 6
  • atmosphere-runtime 2.4.7

In the web.xml file, I define the servlet for Push:

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>

When I try to get an instance of Eventbus to launch a notification, EventBusFactory returns null :

EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(notificacion.getRuta(), notificacion);

I have investigated the primefaces forums where they indicate that the problem should be solved by entering the <load-on-startup>1</load-on-startup> parameter of web.xml , however it is not my case.

    
asked by hecnabae 13.10.2016 в 16:47
source

1 answer

1

just put the following code for a default constructor

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

Will work for any version

<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>
    
answered by 10.01.2017 в 21:47