本文介绍了PrimeFaces套接字如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

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

#1. uview是指视图作用域的bean.除侦听器方法外,其他所有功能(包括更新)均有效.侦听器方法永远不会被调用.即使我将侦听器的值更改为不存在的方法,也不会报告任何错误.知道为什么它不起作用吗?

#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?

我在以下代码段中注意到的另一件事[涉及动态ID]:

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>

在这里,它报告错误,指出找不到指定ID的ID [显示错误消息中的ID].即使存在具有该ID的元素,也无法找到该元素.这当然不是命名容器参考问题.

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.

之所以会这样,是因为即使在JSF& ;;呈现page [dynamic part]之前,Primeface套接字也已初始化.这就是为什么它找不到动态ID的原因?

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.正如我从Pimeface演示页面上所了解的那样,需要使用动态ID更新元素才能在JSF中实现聊天应用程序.我在实现primeface套接字时会出错吗?还有其他方法可以更优雅地实现它吗?

#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?

推荐答案

这是一个错误.我发现以下解决方法:像这样的代码

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>

替换为:

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

这篇关于PrimeFaces套接字如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:02
查看更多