Question

Is there a way (in JSF 2) to catch a Conversation timeout and redirect a user to a new page? I'm getting nasty NullPointerExceptions when the conversation times out.

I could redirect the user on all NPE's, but that seems like too big a net.

Was it helpful?

Solution

This is a bug with Weld 1.0.0 the RI for CDI

https://jira.jboss.org/browse/WELD-550

This has apparently been fixed in the Weld trunk, I don't know in which release it's available. In trunk, a org.jboss.weld.context.NonexistentConversationException exception is thrown, when trying to access an expired conversation. This Exception can be trapped with a custom ExceptionHandler, and redirect the user to an appropriate page. See this blog for more details on creating an custom ExceptionHandler:

http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2

OTHER TIPS

I'm also currently working with CDI-conversations and trying to build a Conversation-based app. I solved most of the problems (not easy without any useful tutorial out there...). Maybe i can help.

My first problem was that i didn't redirect the view&add the cid to GET when navigating to the next page of the Conversation-UseCase. I asked a related question in the Weld Forum. There i learned that in my managed/weld-bean i have to redirect to the next page and add the cid as a GET-parameter. Only then you can access conversation-scoped elements of your bean on the next page.

So when i enter the first page of my conversation i'm calling a start-method (e.g. by a commandLink) in my ConversationScoped-Bean, like this:

public String startRegister() {
  if (conversation.isTransient)
    conversation.begin();
  return "register_start?faces-redirect=true&includeViewParams=true&cid=" + conversation.getId()
}

Does that solve your problem? I also asked a question at StackOverflow related to the ViewExpiredException that has to be handled when working with conversations - here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top