从@ApplicationScoped bean更新p:growl,侦听p:socket [英] Update p:growl from @ApplicationScoped bean listening on p:socket

查看:78
本文介绍了从@ApplicationScoped bean更新p:growl,侦听p:socket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在侦听Web套接字的应用程序范围的Bean.收到消息后,我想更新咆哮声.但是下面这样的方法不起作用,因为它不在请求/响应时间内.有可能这样做吗?

I have application scoped bean that is listening to web-socket. When message is received I would like to update growl. But something like below doesn't work because it is not in request / response time. It is possible to do this?

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

推荐答案

您需要做的是将Bean的PrimeFaces推送事件发送到所有客户端共享的常规Websocket上的所有已连接客户端.在这种情况下,您发送的消息类似于 PrimeFaces推送通知示例

What you need to do is send a PrimeFaces push event from the bean to all attached clients on a general websocket shared by all clients. In that event you send a message like in the PrimeFaces push notify example

 public void send() {
    EventBus eventBus = EventBusFactory.getDefault().eventBus();
    eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
}

然后在页面中显示该消息

And then in the page show that message

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

这篇关于从@ApplicationScoped bean更新p:growl,侦听p:socket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆