Is the conversation area a suitable replacement for the presentation area?

In JSF 2.0, the most obvious use case for the viewport is a stand-alone page with potentially numerous AJAX post-spins. Using CDI instead of managed JSF beans leaves us without scope, so we either remain to implement our own, or use a (possibly fixed) third-party implementation, or use the talk area.

My question is: Is the conversation area a worthy replacement for the presentation area in a typical AJAX situation? Like the viewport, does it allow multiple instances per session? What are the pitfalls?

I know about one of the errors, namely that the conversation area is not automatically deleted when the user navigates from the page, but instead is deleted after a timeout. But I'm not sure what will happen when the user goes to this page before the talk time expires.

UPDATE

The conversation area does support multiple instances per session. This book says so much, and I was able to confirm this using the code from ch. 2.

+8
java jsf-2 cdi conversation-scope
source share
1 answer

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.

+4
source share

All Articles