Long polling (pending request) for JSF

人盡茶涼 提交于 2019-12-13 02:37:00

问题


I need to implement long polling or pending request for a chatroom. I tried a4j:push, but it seems doesn't work like a real long polling approach (see the following discussion: https://community.jboss.org/message/16614).

The question is: which alternatives do I have to realize long polling?

I'm using JSF 1.2, JAVA EE 6 and RichFaces 3.3.2.

Thaks in advance!


回答1:


You need to use the a4j:poll component from RichFaces. The exadel live demo has a very nice sample and explains the main properties. Plus, you can get more info in the official documentation.

Maybe you want to look at a chat implementation example and not polling. There is a question about it:

https://stackoverflow.com/a/1577486/1065197




回答2:


Try to use netty-socketio java project. It has long polling support. Use Socket.IO client javascript lib on your jsf page.

Javascript lib usage example:

<script type="text/javascript">
    var socket = io.connect('http://localhost:81', {
      'transports' : [ 'xhr-polling' ],
      'reconnection delay' : 2000,
      'force new connection' : true
    });
    socket.on('message', function(data) {
         // here is your handler on messages from server
    });

    // send object to server
    var obj = ...
    socket.json.send(obj);
</script>


来源:https://stackoverflow.com/questions/9636874/long-polling-pending-request-for-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!