3

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 :)

StepTNT
  • 3,867
  • 7
  • 41
  • 82
  • 1
    this is not suitable for JSF + PrimeFaces, instead try using jquery. Here is a sample: http://code.google.com/p/jquery-stream/wiki/ChatExample – Luiggi Mendoza Apr 22 '12 at 21:00
  • Thanks for the link. You're saying that there's no JSF library that can handle it? Neither ICEFaces or RichFaces? Because I can't really use jQuery in my project! – StepTNT Apr 23 '12 at 06:56
  • what I'm saying is that push/poll components are not very good to handle chat applications for real time chat. Instead, you should use something lighter and jquery provides that. Anyway, you can try using JSF + RichFaces push and poll (check the poll sample http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf? but the refresh time isn't really as fast as you could think) – Luiggi Mendoza Apr 23 '12 at 14:54
  • I know, but t's just an assignment for my exam, so I don't need it to have the best performances! I'm already using PrimeFaces' poll, but I was wondering if there was a way to it without the insane amount of requests generated by poll :) – StepTNT Apr 23 '12 at 17:28
  • As I've already commented, no – Luiggi Mendoza Apr 23 '12 at 17:55

1 Answers1

1

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.

ntoskrnl
  • 1,545
  • 1
  • 15
  • 25
  • Basically is what I'm already doing using poll. I wanted a push version to avoid making a new request each second! – StepTNT May 20 '12 at 11:34