How PrimeFaces Socket works?

本秂侑毒 提交于 2019-12-23 05:27:41

问题


My code:

<p:socket channel="/allposts/#{uview.user.uid}">
 <p:ajax event="message" async="true" listener="#{uview.go}" update="xout"/>
</p:socket>

#1. uview refers to a view scoped bean. Everything ,including update, works except listener method. Listener method is never invoked. Even if I change the value of listener to a method which is not existing, it isn't reporting any error. Any idea why it isn't working?

Another thing I noticed in the following code snippet[involving dynamic id]:

<p:socket channel="/allposts/#{uview.user.uid}">
<p:ajax event="message" async="true" listener="#{uview.go}" update="#{uview.user.uid}"/>
</p:socket>

Here, it reports error stating that it can't find the id with the specified id[ shows the id in error message]. Even if there's a element with that id, it can't find that. It's certainly not naming container reference problem.

Is it happening because Primeface sockets are initialized even before page[dynamic part] is rendered by JSF & that's why it can't find the dynamic id???

#2. As I've understood from Pimeface Demo page, updating an element with dynamic id is required to implement a chat application in JSF. Am I going wrong here in implementing primeface socket? Are there other ways to implement it more elegantly?


回答1:


uview refers to a view scoped bean. Everything ,including update, works except listener method. Listener method is never invoked. Even if I change the value of listener to a method which is not existing, it isn't reporting any error. Any idea why it isn't working?

It is a bug. I found the following workaround: the code like this

<p:socket channel="/channel">
    <p:ajax event="message"
            listener="#{controller.yourListenerMethod}"
            update=":form:table" />
</p:socket>

replace with:

<p:socket onMessage="handleMessage" channel="/channel" />
<script type="text/javascript">
    function handleMessage(data) {
        updateWidgets();
    }
</script>

<p:remoteCommand name="updateWidgets"
                 actionListener="#{controller.yourListenerMethod}"
                 update=":form:table" />


来源:https://stackoverflow.com/questions/15391190/how-primefaces-socket-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!