JSF/CDI: End Conversation after page renders?

558 Views Asked by At

I have a situation where I have a multi-step wizard rendered using JSF 2.2, and deployed on Wildfly 10/JBoss EAP. Our wizard exists within a CDI Conversation to maintain state across all of the pages. Once the last step of the wizard completes, a record is saved to the database, and I call conversation.end() to end the workflow. I would like to display a value that exists within my Conversation scope to indicate to the user that the process has completed. However, when I end my Conversation, the value obviously goes away because it was set in Conversation scope.

Is there a way to tell CDI to end my Conversation after the final page has completed rendering? Is there a better way to handle the management of the Conversation?

1

There are 1 best solutions below

3
Siliarus On

To my knowledge, there is no way to manipulate conversation scope as you would like to. Unless you could invoke conversation.end() after you redirect the user and display the value. But that would no longer fit into the wizard's lifecycle.

But a relatively simple way around that is using any broader scope that outlives the conversation and storing the value there. To stick with pure CDI, I'd go for @SessionScoped (after all, conversations live within session).

Shortly before you invoke conversation.end(), store the desired value into session scoped bean variable and display it from there.