我正试图在我的项目中实现主推计数器。我正在使用PrimeFaces3.5,Jboss7.0和Eclipse Indigo版本。PrimePush计数器实现
- 气氛的注解-1.0.1.jar
- 大气COMPAT-jbossweb-1.0.1.jar
- 大气COMPAT-tomcat的:
与黄金推我已经加入罐-1.0.1.jar
- 气氛-COMPAT-tomcat7-1.0.1.jar
- 气氛-运行时1.0.1.jar
- primefaces-3.5.jar和JSF和SLF4J罐子
我的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: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>
我管理的bean:
@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自动,因为它没有更新。但是当我刷新页面时,计数会按预期递增。
例外,我得到的是:
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
你没有提到你设置推送的Servlet就像[primefaces用户指南中介绍](http://primefaces.googlecode.com/files/indexed_primefaces_users_guide_3_5.pdf) - 第5章。你配置了它吗? – Jens 2013-04-22 07:13:52
是延,我在web.xml 推的Servlet servlet的名称> org.primefaces.push.PushServlet servlet的类> 的 推的Servlet servlet的名称> /primepush/* url-pattern的> servlet的映射> –
2013-04-22 07:30:44
您尝试在web.xml中配置: 的 Push Servlet servlet-name> org.primefaces.push.PushServlet servlet-class> true async-supported> –
2013-04-22 07:56:50