从侦听 p:socket 的 @ApplicationScoped bean 更新 p:growl

Update p:growl from @ApplicationScoped bean listening on p:socket

我有一个正在侦听网络套接字的应用程序范围的 bean。收到消息后,我想更新咆哮。但是像下面这样的东西不起作用,因为它不在请求/响应时间。有可能这样做吗?

RequestContext.getCurrentInstance().update("growl");
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Message", "value"));

您需要做的是将 PrimeFaces 推送事件从 bean 发送到所有客户端共享的通用 websocket 上的所有附加客户端。在这种情况下,您可以像 PrimeFaces push notify 示例

中那样发送消息
 public void send() {
    EventBus eventBus = EventBusFactory.getDefault().eventBus();
    eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
}

然后在页面中显示该消息

<p:growl widgetVar="growl" showDetail="true" />
<p:socket onMessage="handleMessage" channel="/notify" />

<script type="text/javascript">
    function handleMessage(facesmessage) {
        facesmessage.severity = 'info';

        PF('growl').show([facesmessage]);
    }
</script>