如何在 JSF 组件中监视异步/后台线程状态并获取通知 [英] How to monitor asynchronous/background thread status and get notifications in a JSF component

查看:18
本文介绍了如何在 JSF 组件中监视异步/后台线程状态并获取通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Web 应用程序中创建了几个线程,并且在 JSF 页面中有一个数据表组件.

I created few threads in a web application and I have a datatable component in JSF page.

我想自动更新表格以显示线程的当前状态.在这种情况下,我可以使用任何预构建组件吗?

I would like to update the table automatically to show the current status of thread. Is there any prebuild component I can use in this scenario?

推荐答案

我在 Web 应用程序中创建了几个线程

我衷心希望你 以正确的方式做到了,因此它不会以史诗般的灾难告终.

I wholeheartedly hope that you did it the right way and thus it don't end up in an epic disaster.

我想自动更新表格以显示线程的当前状态.在这种情况下,我可以使用任何预构建组件吗?

您基本上是在寻找一种称为轮询"的技术;或推".轮询的基本概念是使用 JavaScript 的 setInterval()setTimeout() 每隔一段时间向服务器发出(ajax)HTTP 请求,并让它相应地处理结果.推送的基本概念是打开一个持久的 HTTP 连接并让服务器通过它发送小消息,这可以通过 JavaScript 中的WebSocketJava EE 7 中的 JSR356 API.

You're basically looking for a technique called "polling" or "pushing". The basic concept of polling is to use JavaScript's setInterval() or setTimeout() to fire a (ajax) HTTP request to the server at intervals and let it process the results accordingly. The basic concept of pushing is to open a persistent HTTP connection and have the server send small messages over it, this can be done with among others WebSocket in JavaScript and JSR356 API in Java EE 7.

标准的 JSF 实现不提供任何现成的轮询或推送组件.对于即将发布的 JSF 2.3,一个新的 <f:websocket> 标签目前正在开发中(另见 问题 1396).

The standard JSF implementation doesn't offer any ready-to-use poll or push component out the box. For the upcoming JSF 2.3, a new <f:websocket> tag is currently in progress (see also issue 1396).

你最好的选择是一个带有隐藏命令链接/按钮的隐藏表单,带有 ,然后通过 setInterval() 调用它.像 PrimeFaces 这样的组件库提供开箱即用的组件,另见 展示 展示 一些具体的例子.JSF 实用程序库 OmniFaces 在其 <o:commandScript> 展示 投票示例和 展示几个推送示例(新标准 JSF 将主要基于).

Your best bet would be a hidden form with a hidden command link/button with <f:ajax> and then invoke it by setInterval(). Component libraries like PrimeFaces however offer ready-to-use components out the box, see also <p:poll> showcase and <p:push> showcase for some concrete examples. JSF utility library OmniFaces has in its <o:commandScript> showcase a poll example and in <o:socket> showcase several push examples (the new standard JSF <f:websocket> will be largely based on <o:socket>).

这篇关于如何在 JSF 组件中监视异步/后台线程状态并获取通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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