我最近从Primefaces 4.0升级到5.0,而且我无法使用推送消息来使用5.0。我的服务器是Glassfish 4.0,浏览器是Firefox 29.0.1
我已将问题简化为一个非常简单的示例,该示例遵循用户指南中的示例。当我单击按钮发送消息时,端点已成功接收,但我收到javascript错误,文本未更新。这是错误:
与ws:// localhost:26293 / pushtest / primepush / mytest的连接?X-Atmosphere-tracking-id = 0& X-Atmosphere-Framework = 2.2.0-javascript& X-Atmosphere-Transport = websocket& X-Atmosphere-TrackMessageSize = true& X-Cache-Date = 0& X-atmo-protocol = true在页面加载时被中断。
我的页面:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" >
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</h:head>
<h:body>
<h:form>
<h:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>
<p:socket channel="/mytest" onMessage="handleMessage" >
</p:socket>
<h:outputText styleClass="messageDisplay" id="test1" value="hello text"/>
</h:form>
<script type="text/javascript">
// <![CDATA[
function handleMessage(data) {
$('.messageDisplay').text(data);
} // ]]>
</script>
</h:body>
Backing Bean:
@Named
@ApplicationScoped
public class TestBean {
public void sendMessage() {
Date now = new Date();
System.out.println("sending message, now: "+now);
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/mytest", "complete "+now);
}
}
Push Endpoint:
@PushEndpoint("/mytest")
public class PushEndPoint {
@OnMessage(encoders= {JSONEncoder.class})
public String onMessage(String msg) {
System.out.println("received msg: "+msg);
return msg;
}
}
配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Maven Dependencies:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
</dependencies>