golinko
golinko

Reputation: 347

Long polling (pending request) for JSF

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!

Upvotes: 1

Views: 1800

Answers (2)

Nikita Koksharov
Nikita Koksharov

Reputation: 10793

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>

Upvotes: 0

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

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

Upvotes: 1

Related Questions