并在JSF组件收到通知

并在JSF组件收到通知

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

问题描述

我在Web应用程序中创建的线程数,我在JSF页面的DataTable组成部分。

我想自动更新该表,以显示线程的当前状态。是否有任何prebuild分量,我可以在这种情况下使用?


解决方案

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


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.

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

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

See also:

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

08-01 05:43