我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