Primepush on primfaces 3.4 – making it work

Posted: October 24, 2012 in web

Jetty server not needed on 3.4

web.xml (note on web-app, its using version 3.0 and add async-supported)


<web-app version="3.0"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
...

<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>

POM


<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.0.RC1</version>
</dependency>

Backing bean


package org.primefaces.examples.view;

import java.io.Serializable;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextFactory;

public class GlobalCounterBean implements Serializable{

private int count;

public int getCount() {
 return count;
 }

public void setCount(int count) {
 this.count = count;
 }

 public synchronized void increment() {
 count++;

 PushContext pushContext = PushContextFactory.getDefault().getPushContext();
 pushContext.push("/counter", String.valueOf(count));
 }
}

xhtml:


<h:form id="form">
 <h:outputText id="out" value="#{globalCounter.count}" styleClass="ui-widget display" />

<br />

<p:commandButton value="Click" actionListener="#{globalCounter.increment}" />
</h:form>

<p:socket onMessage="handleMessage" channel="/counter" />

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s