首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrimePush计数器实现

PrimePush计数器实现
EN

Stack Overflow用户
提问于 2013-04-22 06:57:47
回答 2查看 2.6K关注 0票数 2

我正试图在我的项目中实现主要的推送计数器。我正在使用PrimeFaces3.5、Jboss7.0和Eclipse版本。

我增加了与主要推送相关的罐子:

  1. atmosphere-annotations-1.0.1.jar
  2. atmosphere-compat-jbossweb-1.0.1.jar
  3. atmosphere-compat-tomcat-1.0.1.jar
  4. atmosphere-compat-tomcat7-1.0.1.jar
  5. atmosphere-runtime-1.0.1.jar
  6. primefaces-3.5.jar、jsf和slf4j jars

我的xhtml代码:

代码语言:javascript
复制
<?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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
    <h:form id="form">
        <h:outputText id="out" value="#{pushBean.count}" />
        <p:commandButton value="Click" actionListener="#{pushBean.increment}" />
    </h:form>
    <p:socket onMessage="handleMessage" channel="/counter" />
    <script type="text/javascript">
         function handleMessage(data) {
           $('.display').html(data);
         }
    </script>
</h:body>
</html>

我的托管豆:

代码语言:javascript
复制
@ManagedBean(name = "pushBean")
@ApplicationScoped
public class PushBean {

    public PushBean() {
    }

    private int count;

    public int getCount() {
        return this.count;
    }

    public void setCount(final int count) {
        this.count = count;
    }

    public synchronized void increment() {
        this.count++;
        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
        pushContext.push("/counter", String.valueOf(this.count));
    }

}

当我单击UI中的按钮时,计数会在服务器上递增,但它不会自动反映在UI中,因为它没有被更新。但是,当我刷新页面时,计数会按预期增加。

我得到的例外是:

代码语言:javascript
复制
13:00:02,298 ERROR [stderr] (http--0.0.0.0-8080-5) [http--0.0.0.0-8080-5] ERROR org.atmosphere.cpr.AtmosphereFramework - AtmosphereFramework exception

13:00:02,298 ERROR [stderr] (http--0.0.0.0-8080-5) java.lang.IllegalStateException: The servlet or filters that are being used by this request do not support async operation
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-22 08:33:46

当您的web应用程序在符合Servlet 3的容器中运行时,会发生此异常。正确的web.xml必须将异步支持的元素设置为true,例如:

代码语言:javascript
复制
    <servlet> 
        <servlet-name>Push Servlet</servlet-name> 
        <servlet-class>org.primefaces.push.PushServlet</servlet-class> 
        <async-supported>true</async-supported> 
    </servlet>

参考资料:安装气氛

票数 2
EN

Stack Overflow用户

发布于 2013-04-22 07:12:12

对于push框架,我不太确定,但我认为问题在于您的javascript。您正在尝试刷新" .display“控件,但是没有什么比.display更好。

尝试“.out”而不是.display

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16141150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档