users@javaserverfaces-spec-public.java.net

[jsr372-experts mirror] Re: f:websocket hoisting

From: Rahman USTA <rahman.usta.88_at_gmail.com>
Date: Mon, 13 Feb 2017 21:02:59 +0300

Hi Bauke,

I see the following PR here
https://github.com/javaserverfaces/mojarra/commit/216dadaa80a9353e75781a5cfd010305e078c96d

I also agree with Christian's suggestion.

Thanks

2017-02-13 15:09 GMT+03:00 Christian Kaltepoth <christian_at_kaltepoth.de>:

> Hey Bauke,
>
> thank you very much for your response. Actually I wasn't aware that
> <f:ajax> works inside <f:websocket>. That's really great and simplifies
> many common use cases.
>
> However, I still think that the way custom listeners (onmessage, onopen
> and onclose) are registered should be improved. IMO this is very important
> for integration with modern client side JavaScript. So it would be great to
> have something similar to "jsf.ajax.addOnEvent" for websockets.
>
> Christian
>
> 2017-02-12 20:02 GMT+01:00 Bauke Scholtz <balusc_at_gmail.com>:
>
>> Rahman,
>>
>> Script loading issue was an oversight during transformation of
>> f:websocket from TagHandler to UIComponent. I've fixed it as per
>> https://java.net/jira/browse/JAVASERVERFACES-4225
>>
>>
>> Christian,
>>
>> As to jsf.push.addOnMessage(), a very valid point there.
>>
>> In the meanwhile, you could just embed <f:ajax> in <f:websocket>.
>>
>> <f:websocket>
>> <f:ajax event="push" render="holder" />
>> </f:websocket>
>> <h:outputText id="holder" value="#{bean.message}" />
>>
>> No need for a custom script. Support for this was added in 2.3.0-m09.
>>
>> Cheers, Bauke
>>
>> On Sun, Feb 12, 2017 at 1:20 PM, Christian Kaltepoth <
>> christian_at_kaltepoth.de> wrote:
>>
>>> 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
>>>
>>>
>>
>
>
> --
> Christian Kaltepoth
> Blog: http://blog.kaltepoth.de/
> Twitter: http://twitter.com/chkal
> GitHub: https://github.com/chkal
>
>


-- 
Rahman USTA
Istanbul JUG
https://github.com/rahmanusta