0

Since PrimeFaces have deprecated Push I'm trying to get JSF 2.3 working om GlassFish 5. I'm having trouble firing my listener though.

I have the following code:

@Inject
@Push(channel = "notifyjsf")
private PushContext push;

push.send("price");
logger.log(Level.INFO, "price push");

My problem is firing my notify function. If I set onmessage as follows it doesn't fire at all:

<f:websocket channel="notifyjsf" onmessage="notifyListener" />

Also I get a warning from IntelliJ that "Expression statement is not assignment or call"

However, if I do this:

<f:websocket channel="notifyjsf" onmessage="notifyListener(message,channel,event)" />

The listener is fired but I get an error:

"VM36:1 Uncaught ReferenceError: message is not defined
at eval (eval at <anonymous> (jquery.js.xhtml?ln=primefaces&v=6.1:14), <anonymous>:1:172)

My listener code is below

function notifyListener(message, channel, event) {
        console.log("notifyListener message: " + message);
        console.log("notifyListener channel: " + channel);
        console.log("notifyListener event: " + event);

        console.log("stocks: notifyListener");

    }

Thanks, Zobbo

zobbo
  • 117
  • 2
  • 13
  • Start reading here:https://javaserverfaces.github.io/docs/2.3/javadocs/javax/faces/push/Push.html contains relevant info with differences to your case. (And don't always believe your IDE, but just run it) – Kukeltje Feb 08 '20 at 21:08
  • Thanks, I've looked at the doc and can't really see what I'm doing wrong if I use the correct event listener (without arguments for onmessage) e.g. It's still not firing at least. – zobbo Feb 17 '20 at 21:10
  • After adding onopen and onclose listeners, onopen is fired but not onclose or on message – zobbo Feb 18 '20 at 19:28
  • 1
    I've actually got this working now. I think it was a timing issue. Once I did the push later it worked (after initialisation). Thanks for pointing to the documentation it helped me debug. – zobbo Feb 18 '20 at 20:19
  • Great it works. Maybe it is good to create an answer with code and specifically the new position of push and improve the question so the difference is clear to others – Kukeltje Feb 18 '20 at 21:52

0 Answers0