1

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:

  1. 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?
  2. Is it possible to create a PrimeFaces dialog dynamically from JavaScript> Or maybe there is better solution to do it?

1 Answer 1

1

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 channel between 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 on jetty server.

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

Sign up to request clarification or add additional context in comments.

2 Comments

Well, you doesn't really answer my questions. Messenger is just a context of my problem which is creating dialogs from JavaScript. By the way, thank you for the information you provided but I think for a little number of users, storing messages in database and using ajax poll in client would be enough.
@rotman strictly to your problem, you do not have to create a dialog dynamically...you just have to implement a dialog component and show it everytime you need(some render attribute set to false and an update would be enough)...explain me more, if I haven't understood you problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.