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>
Code: Select all
public void startLongRunningProcess() {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/realtime", "{ 'progress' : 10, 'msg' : 'Please Wait'}");
}
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);
}
}