title: EventBusFactory JSF1073
body: <p>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 <a href="http://www.primefaces.org/showcase-labs/push/viewparam.jsf?data=Pushed" rel="nofollow noreferrer">primefaces pushdata showcase</a></p>
  
  <h2>XHTML:</h2>
  
  <pre><code>&lt;f:view&gt;
                  &lt;h:form id="form"&gt;
                      &lt;f:metadata&gt;
                          &lt;f:viewParam name="data" value="#{viewParamPush.data}" /&gt;
                          &lt;f:event type="preRenderView" listener="#{viewParamPush.prerender}" /&gt;
                      &lt;/f:metadata&gt;
  
                      &lt;h:outputText id="out" value="#{viewParamPush.data}" style="font-size:16px" /&gt;
  
                      &lt;p:socket onMessage="handleMessage" channel="/QR" /&gt;
  
                      &lt;script type="text/javascript"&gt;
                          function handleMessage(data) {
                              $('#out').text(data);
                          }
                      &lt;/script&gt;
                  &lt;/h:form&gt;
              &lt;/f:view&gt;
  </code></pre>
  
  <h2>ViewParamPush:</h2>
  
  <pre><code>    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);
      }
  }
  </code></pre>
  
  <h2>ViewParamResource:</h2>
  
  <pre><code>@PushEndpoint("/QR")
  public class ViewParamResource {
  
      @OnMessage(encoders = {JSONEncoder.class})
      public String onMessage(String data) {
           util.sysprint("ViewParamResource onMessage", true);
          return StringEscapeUtils.escapeHtml4(data);
      }
  }
  </code></pre>
  
  <p>I get the following exception when <strong>eventBus.publish("/QR", data);</strong> 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?</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>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</p>
  
  <pre><code>&lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
          **&lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;**
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <h2>Dependencies:</h2>
  
  <pre><code> &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces&lt;/groupId&gt;
              &lt;artifactId&gt;primefaces&lt;/artifactId&gt;
              &lt;version&gt;5.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.extras&lt;/groupId&gt;
              &lt;artifactId&gt;appserv-rt&lt;/artifactId&gt;
              &lt;version&gt;3.1.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- http://mvnrepository.com/artifact/org.atmosphere/atmosphere-runtime --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.atmosphere&lt;/groupId&gt;
              &lt;artifactId&gt;atmosphere-runtime&lt;/artifactId&gt;
              &lt;version&gt;2.4.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.marklogic&lt;/groupId&gt;
              &lt;artifactId&gt;java-client-api&lt;/artifactId&gt;
              &lt;version&gt;3.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;  
              &lt;groupId&gt;org.primefaces.themes&lt;/groupId&gt;  
              &lt;artifactId&gt;cupertino&lt;/artifactId&gt;  
              &lt;version&gt;1.0.10&lt;/version&gt;  
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces.extensions&lt;/groupId&gt;
              &lt;artifactId&gt;primefaces-extensions&lt;/artifactId&gt;
              &lt;version&gt;4.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.helger&lt;/groupId&gt;
              &lt;artifactId&gt;ph-schematron&lt;/artifactId&gt;
              &lt;version&gt;3.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.lowagie&lt;/groupId&gt;
              &lt;artifactId&gt;itext&lt;/artifactId&gt;
              &lt;version&gt;2.1.7&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bcprov-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bcmail-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bctsp-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi&lt;/artifactId&gt;
              &lt;version&gt;3.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
              &lt;version&gt;3.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.barcode4j&lt;/groupId&gt;
              &lt;artifactId&gt;barcode4j-light&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.glxn&lt;/groupId&gt;
              &lt;artifactId&gt;qrgen&lt;/artifactId&gt;  &lt;!-- QR code support --&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>