Reputation: 3967
I'm trying to add some features to my webapp, something like a "live user-to-user" chat (like Facebook's one) and a realtime notifications system.
Let's consider this scenario : We've got two users, A and B.
A sends a message to B.
If the chat window between B and A is opened on B's browser, we update it, showing the new message on B's browser. If the windows's not opened, we need to show a notification or something on B's browser.
So, having a PrimeFaces Dialog as the chat window and a PrimeFaces NotificationBar to show notifications, how can I do that?
I can't use PrimeFaces' push as they don't work with Glassfish.
I've found out about ICEPush, that seems to be a nice way to do this, but the thing about "Rendering groups" stopped me from trying it. How can I update just a SINGLE client if ICEPush talks about groups?
Should I create a new group for each client?
Something like : B has a "BwithA" group that is updated when A sends a message to B and the chat is opened, and a "notificationsB" group that is updated when the chat windows is closed?
I can't find out how to do that because, even using groups this way, is A that has to tell B that he needs to update, and A doesn't know if B has to update the dialog or the notificationBar !
I hope that the question is clear, because it's not easy to explain it|
Thanks in advance :)
Upvotes: 3
Views: 6021
Reputation: 1635
I don't know how a professional Java programmer would solve your problem, but when I wanted to create a chat, I used standard Primefaces Remote Command component and call-back parameters to create chat and send new messages to user's from the server.
There is a p:remoteCommand
component on web-page. The purpose of the component is to get the latest messages from a particular user when action listener is invoked. New messages are passed from the server to javascript function (handler of oncomplete
event of the component) via "call-back parameters". The function then checks if there are any messages and appends them to the chat box.
For more information, see How to create JSF chat with AJAX
UPD: the solution above is outdated. Now I would use JAX-RS web-services or web sockets to implement chat. There is also a commercial solutions for real-time data streaming: PubNub, Pusher, etc.
Upvotes: 1