NPE in EventBusFactory.getDefault().eventBus();

UI Components for JSF
Post Reply
Spearhead
Posts: 31
Joined: 17 Jul 2013, 13:22

25 Sep 2015, 10:54

Hi All,

Anyone faces this issue before? when i put EventBusFactory.getDefault().eventBus(); in Backing, its working fine. BUT, when i moved to Service layer, it throw NPE. Anyone can help?

Below is my code:

XHTML:

Code: Select all

<div>
		<p:panel id="panel" header="">
			<p:commandButton id="btn" value="Start"
				actionListener="#{jobDetailBacking.startLongRunningProcess}">
			</p:commandButton>
		</p:panel>

		<p:blockUI block="panel" trigger="btn">
			<p:progressBar widgetVar="progressBar" style="width:300px"
				update=":form:progressBar" labelTemplate="{value}%">
			</p:progressBar>
		<span id="msg"></span>
		</p:blockUI>
</div>

<p:socket channel="/realtime" onMessage="handleProgress"></p:socket>

	<script type="text/javascript">
		function handleProgress(progressJson) {
			//alert('begin');
			var progressData = eval("(" + progressJson + ")");
			PF('progressBar').setValue(progressData.progress);
			$("#msg").text(progressData.msg);
	 }
	</script>
Backing:

Code: Select all

public void startLongRunningProcess() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/realtime", "{ 'progress' : 10, 'msg' : 'Please Wait'}");
    }
PushResource:

Code: Select all

package com.triaset.spearhead.dayend.backing;

import org.apache.commons.lang3.StringEscapeUtils;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.annotation.Singleton;
import org.primefaces.push.impl.JSONEncoder;

@PushEndpoint("/realtime")
@Singleton
public class PushResource {
    @OnMessage(encoders = {JSONEncoder.class})
    public String onMessage(String data) {
        return StringEscapeUtils.escapeHtml4(data);
    }
}
Appreciate if someone can help. Thank You.
PrimeFaces 6.2, Extensions 6.2.7
jsf Mojarra 2.2.8
JBoss 8.2 WildFly Final

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

29 Sep 2015, 20:43

Spearhead wrote:when i put EventBusFactory.getDefault().eventBus(); in Backing, its working fine. BUT, when i moved to Service layer, it throw NPE.

Backing:

Code: Select all

public void startLongRunningProcess() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/realtime", "{ 'progress' : 10, 'msg' : 'Please Wait'}");
    }
1. Please reply with the scope of the bean for the 'Backing' (@applicationscoped, @requestscoped, @sessionscoped, ...)

2. Please clarify 'Service layer'. Is this an @EJB, MDB, or scoped bean? Would be nice to see more of your code.

FYI, I declared the following in @ApplicationScoped bean, added methods on @ApplicationScoped bean to reference the following,

Code: Select all

private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
and of course, I call the @ApplicationScoped bean methods in @Singleton beans, MDBs, and request/session scoped beans... to push messages to clients.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Spearhead
Posts: 31
Joined: 17 Jul 2013, 13:22

30 Sep 2015, 04:03

Hi,

1. I am using @ConversationScoped in my backing(WEB Container) as shown below:

This works fine :

Code: Select all

@Named
@ConversationScoped
public class JobDetailBacking extends AbstractBackingBean implements
        Serializable, DataTableLoadable<JobDetail> {

public void startLongRunningProcess() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/realtime", "{ 'progress' : 10, 'msg' : 'Please Wait'}");
    }

}
2. Service layer(EJB Container)

This is not working when i move startLongRunningProcess to service layer(EJB Container), throw NPE :

Code: Select all

@Stateless
@LocalBean
public class DayEndService implements DayEndServiceLocal {

public void startLongRunningProcess() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/realtime", "{ 'progress' : 10, 'msg' : 'Please Wait'}");
    }
}
PrimeFaces 6.2, Extensions 6.2.7
jsf Mojarra 2.2.8
JBoss 8.2 WildFly Final

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

30 Sep 2015, 12:49

See my previous response and try my approach/implementation.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 42 guests