我如何做 Primefaces 6.0 的工作推送 [英] How can I do working push of Primefaces 6.0

查看:26
本文介绍了我如何做 Primefaces 6.0 的工作推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个 push 功能,但这个简单的代码不起作用:http://www.primefaces.org/showcase/push/counter.xhtml

I need a push functionality but this simple code not working: http://www.primefaces.org/showcase/push/counter.xhtml

我需要一些特定的库?

下一个代码是我的;与primefaces页面相同.

The next code is the mine; the same of the primefaces page.

CounterResource.java:

CounterResource.java:

import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;

@PushEndpoint("/counter")
public class CounterResource {

    @OnMessage(encoders = {JSONEncoder.class})
    public String onMessage(String count) {
        return count;
    }
} 

GlobalCounterView.java

GlobalCounterView.java

import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;

@ManagedBean
@ApplicationScoped
public class GlobalCounterView implements Serializable{

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

index.xhtml:

index.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"

      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form id="form">
            <h:outputText id="out" value="#{globalCounterView.count}" styleClass="ui-widget display" />

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

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

        <script type="text/javascript">
            function handleMessage(data) {
                $('.display').html(data);
            }
        </script>
    </h:body>
</html>

我的 web.xml:

My web.xml:

<?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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <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>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

请帮帮我.谢谢!

推荐答案

PrimeFaces Push 在 6.3 中被移除,你可以在这张票中看到:https://github.com/primefaces/primefaces/issues/3385

PrimeFaces Push was removed in 6.3 you can see in this ticket: https://github.com/primefaces/primefaces/issues/3385

您可以了解 PrimeFaces 决定删除它的原因:https://www.primefaces.org/primefaces-6-2-roadmap/

You can read why PrimeFaces decided to remove it: https://www.primefaces.org/primefaces-6-2-roadmap/

PrimeFaces Push 在底层使用了大气框架,因为 JSF2.3提供了socket组件,我们相信是时候淘汰Push了.与移动设备一样,推送将在 6.2 中弃用,并在 6.3 中移除.

PrimeFaces Push uses atmosphere framework under the hood and since JSF 2.3 provides a socket component, we believe it is time to retire Push. As with mobile, push will be deprecated in 6.2 and removed in 6.3.

总而言之,我们希望将更多的时间花在核心上组件和功能.

In summary, we’d like to focus and spend our time more on the core components and features.

因此您的代码必须引用 Push,它使用 6.3-SNAPSHOT 解释了 Class Not Found 错误.

So your code must be referencing Push which explains the Class Not Found error using 6.3-SNAPSHOT.

这篇关于我如何做 Primefaces 6.0 的工作推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆