Ferramentas:
Glassfish 4.0
Netbeans 8.1
jdk 1.7
primefaces 5.0
dependencias
Configurações no web.xml:
configuração no glassfish:
backBean:
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.apache.commons.lang.StringEscapeUtils;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;
@ManagedBean
@RequestScoped
public class NotifyView {
private final static String CHANNEL = "/notify";
private String summary;
private String detail;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public void send() {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
}
}
E agora é só complilar.
OBS: o glassfish nem sempre conserva o estado do COmet, por isso a verificação é sempre necessaria.