First of all, I'm using Primefaces 5.1, Primefaces PUSH 2.0, Glassfish 4.1, JSF 2.2 in my project.
The WebSocket works fine but only after cleaning cache by pressing CTRL + F5. If I don't, the browser crashes and I get the following messages (that's why it only works after CTRL + F5):
Code: Select all
GET http://localhost:8080/zzz/javax.faces.resource/socket/socket.css.jsf?ln=primefaces&v=5.1 2015-02-11 13:55:08.854jquery.js.jsf?ln=primefaces&v=5.1:25
GET http://localhost:8080/zzz/javax.faces.resource/socket/socket.js.jsf?ln=primefaces&v=5.1 404 (Not Found)
I'm using facelets in my xhtml files. So, I have a main-template.xhtml where I've put the JavaScript to handle the WebSocket requests, as you can see below:
Code: Select all
<h:head>
<!-- some stuff here... -->
<script type="text/javascript">
console.log('> Alive');
function handleMessage(data) {
/*data.severity = 'info';
PF('growl_info_wdgt').show([data]);*/
console.log('handleMessage - ' + data);
receiveMessage([{name:'msgData', value:data}]);
}
function handleOpen(data) {
console.log('handleOpen - ' + data);
}
function handleClose(data) {
console.log('handleClose - ' + data);
}
/*I've seen this code as workaround approach for a
similar problem with Primefaces Mobile, as you can see
in this link: http://stackoverflow.com/questions/27645923/why-is-my-pprogressbar-not-displayed-only-the-number/27667540#27667540
Without using this workaround, the message error is the
same as shown in the previous link;
*/
var originalPrimeFacesCw = PrimeFaces.cw;
PrimeFaces.cw = function(name, id, options, resource) {
resource = resource || name.toLowerCase();
originalPrimeFacesCw.apply(this, [name, id, options, resource]);
};
</script>
</h:head>
Code: Select all
<p:socket
channel="/zzz"
onMessage="handleMessage"
/>
Thanks in advance.