从p:socket上的@ApplicationScoped bean更新p:growl

时间:2015-04-07 12:17:42

标签: jsf primefaces websocket growl

我有正在侦听web-socket的应用程序作用域bean。收到消息后,我想更新咆哮。但是下面的内容不起作用,因为它不在请求/响应时间内。有可能这样做吗?

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

1 个答案:

答案 0 :(得分:1)

您需要做的是将Bean中的PrimeFaces推送事件发送到所有客户端共享的常规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>