3

p:dataTable在每一行中显示了一种金融工具和实时价格,我想使用 设置广播频道p:socket,每行一个频道。目标是当单一仪器的新价格到来时,我只能更新其单元以获得更好的性能。

首先,我尝试从展示的聊天示例中复制聊天示例,并从服务器端订阅动态频道,但是这样客户端无法获取消息所在的频道(并且确实p:socket处理多个频道?)。

然后,我尝试插入p:socket数据表:

<p:dataTable var="instrument"  … >
    <p:socket onMessage="handleMessage(#{instrument.id})" channel="/price" autoConnect="false" 
                                      widgetVar="subscriber_#{instrument.id}" /> 
    …
</p:dataTable>

在服务器端:

for (Instrument instrument : instruments) {
    RequestContext.getCurrentInstance().execute("subscriber_" +instrument.getId() + ".connect('/" + instrument.getId() + "')");
}

但这会在客户端引发错误:

ReferenceError: subscriber_123 is not defined

还有其他方法吗?我在客户端或服务器端管理订阅都没有问题,唯一重要的是我不想将所有价格推给所有客户端。

使用 PrimeFaces 3.4.1

4

1 回答 1

0

如果您仍然无法使其工作,以下是您可以动态订阅/连接到频道的方法。

RequestContext.getCurrentInstance().execute("subscriber.connect('/" + instrument.getId() + "')");

您不需要在数据表中有多个<p:socket>。单个套接字足以处理您的所有 pub/sub。

于 2014-01-02T09:12:03.853 回答