Hey all,
I agree with Rahman that this is pretty weird behavior. But I guess this is
more an implementation issue than a spec issue.
However, I would like to note that in my view the current way to specify
message callbacks isn't very nice. Especially because developers have to
define callback functions in the global scope, which is considered as bad
practice in modern JavaScript development.
What about something like this:
<f:websocket id="mySocket" channel="push" />
<script type="application/javascript">
// register callback using the client id
jsf.push.addOnMessage('mySocket', function(message)) {
// process message
});
</script>
With this API developers won't have to define any global callback functions
and they can even dynamically add more listeners at runtime if required. It
is somehow similar to "jsf.ajax.addOnEvent()", but would always refer to a
specific "<f:websocket>" using the clientId.
Thoughts?
Best regards
Christian
2017-02-04 13:12 GMT+01:00 Rahman USTA <rahman.usta.88_at_gmail.com>:
> Hello,
>
> I'm trying JSF 2.3's new WebSocket support.
>
> When I declare onmessage function above of <f:websocket declaration, it
> finds referenced function. So the following usage works;
>
> <script type="application/javascript">
> function onMessage(message) {
> document.getElementById('holder').innerText = message;
> }
> </script>
>
> <f:websocket
> channel="push"
> onmessage="onMessage"/>
>
>
> But, when I move the script declaration below the <f:websocket, it doesn't
> find onMessage function. So the following usage doesn't work;
>
> <f:websocket
> channel="push"
> onmessage="onMessage"/>
>
> <script type="application/javascript">
> function onMessage(message) {
> document.getElementById('holder').innerText = message;
> }
> </script>
>
> I think it would be good if the last usage supported.
>
> Thanks.
>
> --
> Rahman USTA
> Istanbul JUG
> https://github.com/rahmanusta
>
--
Christian Kaltepoth
Blog: http://blog.kaltepoth.de/
Twitter: http://twitter.com/chkal
GitHub: https://github.com/chkal