Reputation: 1614
I'm trying to implement logic in JSF that accepts parameters and then updates some output on the xhtml page. The following is all borrowed from the primefaces pushdata showcase
<f:view>
<h:form id="form">
<f:metadata>
<f:viewParam name="data" value="#{viewParamPush.data}" />
<f:event type="preRenderView" listener="#{viewParamPush.prerender}" />
</f:metadata>
<h:outputText id="out" value="#{viewParamPush.data}" style="font-size:16px" />
<p:socket onMessage="handleMessage" channel="/QR" />
<script type="text/javascript">
function handleMessage(data) {
$('#out').text(data);
}
</script>
</h:form>
</f:view>
ManagedBean
@RequestScoped
public class ViewParamPush implements Serializable{
private String data;
public String getData() {
return data;
}
public void setData(String data) {
util.sysprint("setData " + data, true);
this.data = data;
}
public void prerender() {
util.sysprint("prerender", true);
EventBus eventBus = EventBusFactory.getDefault().eventBus();
util.sysprint("prerender2", true);
even
tBus.publish("/QR", data);
util.sysprint("prerender3", true);
}
}
@PushEndpoint("/QR")
public class ViewParamResource {
@OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String data) {
util.sysprint("ViewParamResource onMessage", true);
return StringEscapeUtils.escapeHtml4(data);
}
}
I get the following exception when eventBus.publish("/QR", data); is called. I understand what a null pointer is however I don't understand why publish("/QR", data); in this case is causing one. Is there something wrong with my syntax?
FATAL: JSF1073: javax.el.ELException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/QR.xhtml @21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
FATAL: /QR.xhtml @21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
javax.el.ELException: /QR.xhtml @21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
I added *.xhtml to the url patterns in order to be able to call the script QR.xhtml?data=some data.. I assume that required in order to pass parameters to the script although I wonder if that affects the publish method
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
**<url-pattern>*.xhtml</url-pattern>**
</servlet-mapping>
<dependencies>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>appserv-rt</artifactId>
<version>3.1.1</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.atmosphere/atmosphere-runtime -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.marklogic</groupId>
<artifactId>java-client-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>cupertino</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-schematron</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bctsp-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j-light</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId> <!-- QR code support -->
<version>1.4</version>
</dependency>
</dependencies>
Upvotes: 0
Views: 1288
Reputation: 570
I've previously encountered this error. The reason for this failure is due to the Atmosphere version.
Then use it as below :
pom.xml
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime-native</artifactId>
<version>2.4.3</version>
</dependency>
web.xml
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
<param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
</init-param>
<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>
This way you can try. It works this for me.
Upvotes: 4