CDI Conversations
amontobin Jan 28, 2019 11:28 AMHi,
I have an old seam application that i need to migrate.
My application uses a lot of conservations and i'm a bit dissappointed with CDI conservations (not as powerful as seam ones).
I need to pass (parameters, entities, ...) from one conversation to the old or to the new one.
For Example,
Query Page (Conversation 1) => Choose Element => Edit Page (Conversation 2 retrieve entity parameter and merge with current persistent context)
In seam, the pseudo algorithm was :
// Get Parameters From current context
Entity entity1 = ...;
Conversation.instance().leave();
Conversation.instance().begin();
// Pass parameters to the new conversation
...
How can i do that in CDI ? I have no access to the old conversation.
I try to do in a jsf action:
String contextId = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(Container.CONTEXT_ID_KEY);
LazyHttpConversationContextImpl httpConversationContext = (LazyHttpConversationContextImpl) Container.instance(contextId).deploymentManager().instance().select(Context.class).select(HttpConversationContext.class).get();
httpConversationContext.activate(oldConversationId);
((MyBean) httpConversationContext.get(bean))
@Inject @Http
ConversationContext conversationContext;
String newConversationId = conversation.getId();
conversationContext.desactivate();
conversationContext.activate(oldConversationId);
((MyBean) conversationContext.get(bean))
conversationContext.desactivate();
conversationContext.activate(newConversationId );
I manage to get rid of warnings :
WELD-000335: Conversation context is already active, most likely it was not cleaned up properly during previous request processing: HttpServletRequestImpl [ POST /xxxx/conversation1.xhtml ]
I can retrieve for basic properties the value used in the previous conversation, but i have got a lot of warnings and i'm not sure that's a good solution at the end.
Maybe should i need to create a custom CDI scope ?
Thanks for sharing your own experience
Sebastien