有没有人设法让wildfly的使用与Primefaces push 2.0合作? Wildfly的原生websockets(jee7)非常适合自己。我不确定如何与primefaces集成。任何例子都会有所帮助。
答案 0 :(得分:1)
我在WildFly 8.1.0.Final上使用了这个:
的pom.xml:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
的web.xml:
<servlet>
<servlet-name>PrimePushServlet</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>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>PrimePushServlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
在.xhtml中:
<p:socket onMessage="handleMessage" channel="/#{request.remoteUser}" />
<script type="text/javascript">
function handleMessage(facesmessage) {
var msgdetail = $.base64.decode(facesmessage.detail);
facesmessage.detail = msgdetail;
PF('growlWidget').show([ facesmessage ]);
}
</script>
我的资源:
@PushEndpoint("/{user}")
@Singleton
public class UserResource {
@PathParam("user")
private String user;
@OnMessage(encoders = { JSONEncoder.class }, decoders = { JSONDecoder.class })
public FacesMessage onMessage(FacesMessage message) {
return message;
}
应修改javascript-part以符合您的需求。
答案 1 :(得分:1)
Wildfly 9.0.2
的pom.xml
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
的web.xml
<servlet>
<servlet-name>PrimePushServlet</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>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>PrimePushServlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
XHTML
<p:socketonMessage="handleMessage" channel="/counter" />
JS
function handleMessage(data) {
console.log(data);
}
爪哇
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/counter")
public class MessageResources {
@OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String count) {
return count;
}
}
更多java
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;
@ManagedBean
@SessionScoped
public class GlobalMessageControler implements Serializable {
private static final long serialVersionUID = -4507223739929042795L;
private volatile int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void increment() {
count++;
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/counter", String.valueOf(count));
}
}