服务器如何能推动通过JSF创建的HTML页面异步的变化? [英] How can server push asynchronous changes to a HTML page created by JSF?

查看:129
本文介绍了服务器如何能推动通过JSF创建的HTML页面异步的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们创建了一个JSF页面,客户端请求允许HTML的新一代动态使用Java code和HTML的组合。
我们可以引入使用JSF框架中的HTML页面挂钩,即允许基于后在服务器上发生的,通常是通过不同的线程异步事件服务器来更新HTML页面?

When we create a JSF page, a client request allows generation of HTML dynamically using a combination of Java code and HTML. Can we introduce hooks in the HTML page using JSF framework, that allow server to update the HTML page based on asynchronous events occurring later at the server, usually via different threads?

推荐答案

直到即将到来的JSF 2.3 < F:WebSocket的> 规范问题1396 ,因为的 Mojarra 2.3.0-M05 ),标准JSF API不为此提供便利。你需要前往的第三方JSF库现在。

Until the upcoming JSF 2.3 <f:websocket> (spec issue 1396, currently already available since Mojarra 2.3.0-m05), the standard JSF API doesn't offer facility for this. You need to head to 3rd party JSF libraries for now.

  • OmniFaces has <o:socket> (JSR356 WebSocket)
  • PrimeFaces has <p:socket> (Atmosphere)
  • ICEfaces has ICEpush (long polling)
  • RichFaces has <a4j:push> (Atmosphere + JMS)

即将到来的JSF 2.3 &LT; F:WebSocket的&GT; 是的很大程度上是基于 &LT;○:插座&GT;

The upcoming JSF 2.3 <f:websocket> is largely based on <o:socket>.

PrimeFaces与RichFaces的使用的罩下的大气(这是很麻烦而不Maven的设置)和RichFaces的增加在它上面的JMS(所以这划伤Tomcat作为它不支持JMS)。大气支持回退到SSE和长轮询的WebSockets。 ICEfaces的是基于古老的长轮询技术。所有那些没有实现它只是后来的Java EE 7中引入本地JSR356的WebSocket API

PrimeFaces and RichFaces use Atmosphere under the hoods (which is troublesome to setup without Maven) and RichFaces adds JMS on top of it (so this scratches Tomcat as it doesn't support JMS). Atmosphere supports websockets with fallback to SSE and long polling. ICEfaces is based on ancient long polling technique. All of those do not implement native JSR356 WebSocket API which was only later introduced in Java EE 7.

OmniFaces使用本地 JSR356的WebSocket API (支持所有Java EE 7的服务器和Tomcat 7.0.27+)。因此也最简单的安装和使用它(一个JAR,一个上下文参数,一个标签和一个注释)。出于安全和JSF视图状态保持的原因,只支持单向推送(服务器到客户端),而不是相反。对于您可以继续使用JSF阿贾克斯通常的方式。

OmniFaces uses native JSR356 WebSocket API (supported in all Java EE 7 servers and Tomcat 7.0.27+). It is therefore also most simple to setup and use (one JAR, one context param, one tag and one annotation). For security and JSF view state keeping reasons, it only supports one-way push (server to client), not the other way round. For that you can keep using JSF ajax the usual way.

另外,你也可以使用轮询,而不是推。 pretty每多了解AJAX JSF组件库有一个&LT; XXX:调查&GT; 组件。这使您可以发送exery X秒一个Ajax请求到服务器,并在必要时更新内容。这仅比推效率低。

Alternatively, you can also use polling instead of pushing. Pretty much every ajax aware JSF component library has a <xxx:poll> component. This allows you to send exery X seconds an ajax request to the server and update the content whenever necessary. It's only less efficient than push.

  • How to monitor asynchronous/background thread status and get notifications in a JSF component
  • Real time updates from database using JSF/Java EE

这篇关于服务器如何能推动通过JSF创建的HTML页面异步的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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