How does PrimeFaces Socket work?

My code:

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

      

# 1. uview is bean scope. Everything, including the update, works except for the listener method. The listener method is never called. Even if I change the value of the listener to a method that doesn't exist, it doesn't report any error. Any idea why it isn't working?

One more thing I noticed in the following piece of code [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 an error indicating that it cannot find the identifier with the specified id [shows the identifier in the error message]. Even if there is an element with this ID, it cannot find it. This, of course, doesn't mention the container reference issue.

This is because the Primeface sockets are initialized even before the page [dynamic part] is rendered by JSF and why can't it find the dynamic id ???

# 2. As I understood on the Pimeface Demo page, implementing a chat application in JSF requires updating the element with a dynamic id. Am I wrong here when you are using a first class socket? Are there other ways of doing it more elegantly?

0


source to share


1 answer


uview is scoped to bean. Everything, including the update, works except for the listener method. The listener method is never called. Even if I change the value of the listener to a method that doesn't exist, it doesn't report any error. Any idea why it isn't working?

This is mistake. I found the following workaround: code like this

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

      



replaced by:

<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" />

      

+4


source







All Articles