Primefaces 推送通知示例不适用于 wildfly 9.0.2
Primefaces Push notify example does not work with wildfly 9.0.2
我尝试在 wildfly 9.0.2 中执行 primefaces push 的通知示例,但不起作用,我搜索了错误,但我找到的答案对我没有帮助,这是我的代码:
感谢您的建议
索引:
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:growl widgetVar="growl" showDetail="true" />
<h:form>
<h:panelGrid columns="2">
<p:outputLabel for="summary" value="Summary: " />
<p:inputText id="summary" value="#{notifyView.summary}" required="true" />
<p:outputLabel for="detail" value="Detail: " />
<p:inputText id="detail" value="#{notifyView.detail}" required="true" />
</h:panelGrid>
<p:commandButton value="Send" actionListener="#{notifyView.send}" />
</h:form>
<p:socket onMessage="handleMessage" channel="/notify" />
<script type="text/javascript">
function handleMessage(facesmessage) {
facesmessage.severity = 'info';
PF('growl').show([facesmessage]);
}
</script>
</h:body>
NotifyView.java:
public class NotifyView {
private final static String CHANNEL = "/notify";
private String summary;
private String detail;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public void send() {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml3(summary), StringEscapeUtils.escapeHtml3(detail)));
}}
NotifyResource.java:
@PushEndpoint("/notify")
public class NotifyResource {
@OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
最后 web.xml:
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
我使用 Wildfly 9.0.2、Primefaces 5.2、commons-lang3-3.4
并尝试大气运行时版本:2.1.7、2.4.0-RC6 和 2.4.5
日志错误:
14:31:29,771 ERROR [io.undertow.request] (default task-24) UT005023: Exception handling request to /Primefaces2_1/primepush/notify: java.lang.NoSuchMethodError: org.atmosphere.cpr.AtmosphereServlet.configureFramework(Ljavax/servlet/ServletConfig;Z)Lorg/atmosphere/cpr/AtmosphereServlet;
at org.primefaces.push.PushServlet.configureFramework(PushServlet.java:67)
at org.primefaces.push.PushServlet.configureFramework(PushServlet.java:36)
at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:80)...
终于找到了解决办法:
使用 atmosphere-runtime-native 和 jboss-as-websockets 库有效。
感谢您对 Xtreme Biker 的帮助
我尝试在 wildfly 9.0.2 中执行 primefaces push 的通知示例,但不起作用,我搜索了错误,但我找到的答案对我没有帮助,这是我的代码:
感谢您的建议
索引:
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:growl widgetVar="growl" showDetail="true" />
<h:form>
<h:panelGrid columns="2">
<p:outputLabel for="summary" value="Summary: " />
<p:inputText id="summary" value="#{notifyView.summary}" required="true" />
<p:outputLabel for="detail" value="Detail: " />
<p:inputText id="detail" value="#{notifyView.detail}" required="true" />
</h:panelGrid>
<p:commandButton value="Send" actionListener="#{notifyView.send}" />
</h:form>
<p:socket onMessage="handleMessage" channel="/notify" />
<script type="text/javascript">
function handleMessage(facesmessage) {
facesmessage.severity = 'info';
PF('growl').show([facesmessage]);
}
</script>
</h:body>
NotifyView.java:
public class NotifyView {
private final static String CHANNEL = "/notify";
private String summary;
private String detail;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public void send() {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml3(summary), StringEscapeUtils.escapeHtml3(detail)));
}}
NotifyResource.java:
@PushEndpoint("/notify")
public class NotifyResource {
@OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
最后 web.xml:
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
我使用 Wildfly 9.0.2、Primefaces 5.2、commons-lang3-3.4 并尝试大气运行时版本:2.1.7、2.4.0-RC6 和 2.4.5
日志错误:
14:31:29,771 ERROR [io.undertow.request] (default task-24) UT005023: Exception handling request to /Primefaces2_1/primepush/notify: java.lang.NoSuchMethodError: org.atmosphere.cpr.AtmosphereServlet.configureFramework(Ljavax/servlet/ServletConfig;Z)Lorg/atmosphere/cpr/AtmosphereServlet; at org.primefaces.push.PushServlet.configureFramework(PushServlet.java:67) at org.primefaces.push.PushServlet.configureFramework(PushServlet.java:36) at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:80)...
终于找到了解决办法:
使用 atmosphere-runtime-native 和 jboss-as-websockets 库有效。
感谢您对 Xtreme Biker 的帮助