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

查看:62
本文介绍了我该如何进行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

我需要一些特定的图书馆吗?

I need some specific library?

下一个代码是我的;与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:

<?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中删除,您可以在此票证中看到:

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在引擎盖下使用了大气框架,并且自JSF起 2.3提供了一个套接字组件,我们认为是时候该退出Push了.与移动设备一样,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天全站免登陆