问题
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