Reading the Conversation ID From Another Parameter

1 minute read

When you are working with a @ConversationScoped bean you may want to read JSF’s conversation ID (cid) from another request parameter such as for example a parameter named state.

At first I tried to find a configuration option to change this behaviour, but failed to find one. In the end the problem can be solved using the org.jboss.weld.context.http.HttpConversationContext class from the Weld CDI implementation if you don’t mind being a little implementation dependent.

This class allows you to activate a specific context ID or cid so you have access to your normal @ConversationScoped beans. The only pitfall here to remember is that you have to call deactivate() first or you may end up with some kind of a Context is already active Exception.

Well you basically do this in your @PostConstruct method.

I admit this is a pretty pragmatic solution, but it seems to work. Maybe the @ConversationScoped needs to let you specify the parameters to read it’s ID from.

Hope this helps, until next time.

Updated: