Primefaces push and Wildfly



有没有人设法让wildfly的暗流与Primefaces的2.0推送一起工作?Wildfly的原生websockets (jee7)独立运行非常好。我不知道怎么和质面积分。任何例子都会有所帮助。

我在WildFly 8.1.0上得到了这个工作。最后:

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

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

}

Java

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));
    }
}

相关内容

  • 没有找到相关文章

最新更新