I am working on a simple messenger using JSF and PrimeFaces. I would like to have contact list in the right part of the window and multiple conversation dialogs in the second part. Dialog will contain just a send button, an input and conversation content.
Use case:
User #1 clicks on contact, chat dialog appears. User #2 is logging to system. System checks that he has 1 unread message so it opens chat dialog. User #2 clicks on another contact and second chat dialog appears.
Questions:
- How to pass some context to dialog like user-you-are-writing-to’s ID so when you click on send button in this particular dialog you will be able to access it?
- Is it possible to create a PrimeFaces dialog dynamically from JavaScript> Or maybe there is better solution to do it?
To create a chat application you have to use a Push Server (and WebSockets) which would be the best solution because you have to create a
channelbetween the user/client and the server (since a simple request is stateless) – and that’s what push does.PrimeFaces Push uses a servlet as a dispatcher. This servlet should be in a different application than the JSF application and at the moment can only be deployed onjettyserver.You could read about this in Primefaces UserGuide 3.0.M4: http://www.primefaces.org/documentation.html
and see this implementation in showcase: http://www.primefaces.org/showcase-labs/push/chat.jsf
Another implementation/example: http://java.dzone.com/articles/creating-websocket-chat