如何在 JSF 中显示服务器生成的消息?
我目前正在使用 spring(webflow)和 jsf(和 primefaces)构建模拟环境。在我的环境中,当服务器触发某些事件时(例如玩家的“现金头寸”已更改),就会生成消息。我希望这些消息每次被触发时都显示在我的网络应用程序中。
我想我必须使用反向 AJAX 之类的东西,但我无法让它在我的应用程序中运行。现在我想知道您是否看到任何其他可能性或技术来实现我的目标。
I'm currently workin' on a simulation environment build with spring (webflow) and jsf (and primefaces). Within my environment messages are generated when some events are triggered by the server (for instance the "cash Position" of a player has changed). I want this messages to be displayed in my webapplication every time they are triggered.
I think I'll have to use someting like reverse AJAX, but I wasn't able to make it run within my application. Now I wanted to know if you see any other possibilities respectively techniques to acheive my goal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用此处显示的组件进行持续的 AJAX 轮询 http://www.primefaces.org /showcase/ui/ajaxPollHome.jsf。
You can do a constant AJAX poll using the components shown here http://www.primefaces.org/showcase/ui/ajaxPollHome.jsf.
在典型的服务器/客户端模型中,TCP 套接字连接将是最好的方法,因为该连接通常保持打开状态,允许服务器和客户端相互双向发送消息。
AJAX 通信本质上是 HTTP 协议,默认情况下是无状态的客户端请求/服务器响应单向模型。
自定义轮询 AJAX 组件(例如从 micfra 链接的组件)是解决此问题的一个很好的示例。自定义轮询组件也可以使用 AJAX 和 Javascript 构建。本质上,客户端需要在这么多时间间隔后向服务器请求状态更新。如果服务器有状态更新或新信息,则可以使用 Javascript 事件更新客户端和服务器上的信息。
In a typical Server/Client model a TCP socket connection would be the best approach because the connection is typically left open allowing the server and client to send messages back and forth to each other bidirectionally.
AJAX communication is essentially HTTP protocol and is by default a stateless Client Request/Server Response unidirectional model.
A custom polling AJAX component like the one linked from micfra is a good example of how to address this problem. A custom polling component can be built with AJAX and Javascript as well. Essentially the client needs to ask the server for status updates after so many intervals. If the server has a status update or new information, then using Javascript events one can update the information on the client as well as the server.