I'm newbies in PrimeFace framework and my projekt needs "push" functionality.
I'v tried test 'notify' and 'counter' from 'showcase' but 'push' don't work.
My lab local PC configuration:
- Win7
Java JDK 1.7.60
GlassFish 4.1 (build 13) (server-config.network-config.protocols.protocol.http-listener-1.http.comet-support-enabled="true")
Mojara 2.2.7
PrimeFaces 5.2
Atmosphere Framework 2.3.1
NetBeans IDE 8.0.2
I tried samples in FireFox 38.0.5 and Internet Explorer 11.0.9600
counter.xhtm (I tried set every kinds params in <p:socket>, I started without params like in 'showcase' )
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>TODO supply a title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="text/javascript">
function handleMessage(data) {
alert("handleMessage");
$('.display').html(data);
}
</script> </head>
<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 channel="/counter"
onMessage="handleMessage"
onLocalMessage="alert('onLocalMessage');"
onMessagePublished="alert('onMessagePublished');"
id="socket"
autoConnect="true"
fallbackTransport="websocket"
onTransportFailure="alert('onTransportFailure');"
/>
</html>
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/counter")
public class CounterResource {
@OnOpen
public void onStart(){
System.out.println("onStart");
}
@OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String count) {
return count;
}
@OnClose
public void onClose(){
System.out.println("onClose");
}
}
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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++;
EventBusFactory ebf=EventBusFactory.getDefault();
EventBus eventBus = ebf.eventBus();
eventBus.publish("/counter", String.valueOf(count));
}
}
Code: Select all
<?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>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</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>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
<param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcaster.maxProcessingThreads</param-name>
<param-value>15</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads</param-name>
<param-value>15</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/counter.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Code: Select all
( @PushEndpoint("/counter")
public class CounterResource ... )
was never called.
I investigated generated HTML code and I found pieces of JavaScript
Code: Select all
"... url:"/Counter/primepush/counter ..."
Code: Select all
'@OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String count) ...'
was called, but no one client (FF or IE) received 'push' message (String count) and included JavaScrpit code no run.
I tried set parameters 'autoConnect=true' and every value from 'fallbackTransport=...' in '<p:socket>', but still nothing.
Showcase from 'http://www.primefaces.org/showcase/push/counter.xhtml' goes OK.
I downloaded 'atmosphere-chat-2.3.1.war' and deployed it and everything goes OK.
I downloaded 'showcase-5.2.war' and deployed it and everything goes OK.
I tried use 'web.xml' from this 'showcase-5.2.war' in my project 'counter', but still nothing.
I tried deploy my 'counter.war' direct to GlassFish server outside NetBeans IDE and still nothing.
Can anybody take me advise, how configure 'push' ?