In any @ConversationScoped CDI beans, you should have the following field:
@Inject private Conversation conversation;
Whenever you want to start a conversation, you need to check if the bean is in transient . Otherwise, an IllegalStateException will be IllegalStateException . It will be something like this:
public void beginConversation() { if (conversation.isTransient()) conversation.begin(); }
This way your bean will be in a long-running state. Therefore, if a user moves along a track from a page and goes back to it, you can always check whether he has a timeout or not, and bring him to the page where he left.
In addition, I used @ViewScoped ManagedBean for a while along with the CDI bean. You can use @Inject to insert a CDI bean in a MangedBean. I donβt think you can do the opposite. In any case, I have no idea if this will lead to what happens later. However, so far I have never encountered any problems. If you really want to use @ViewScoped , I think you can try: P.
UPDATE:
Is a conversation area a worthy replacement for a presentation area in a typical AJAX situation?
I do not think that @ConversationScoped can completely replace @ViewScoped .
Like the viewport, does it allow multiple instances per session?
No, you cannot have multiple instances per session. As I said, if you start a new conversation, and the old conversation is still in a long-running state, you will get an IllegalStateException .
What are the pitfalls?
Well, one of the main advantages of @ViewScoped over @RequestScoped is that you do not need to re-initiate the data every time the user submits the form in the same form. However, with @ConversationScoped , this advantage is overwhelming. Although this problem is not as serious as if you were using @SessionScoped , you still need to hold the initiated data while the @ConversationScoped bean lives. The longer the conversation, the more data you need.