views:

89

answers:

2

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.

A: 

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.

ifischer
Thanks for the feedback, but that's kind of the opposite of what I was hoping to achieve. I wanted to use an `<h:link>` to "escape" a currently long running conversation. This should work according to the spec, see the answer I posted.
Brian Leathem
A: 

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

Brian Leathem
Wow, didn't know that this is a bug. I thought it was me not understanding Weld ;) With the new behavior i can remove some workarounds in my code. Thanks for sharing!
ifischer
Did you already manage to upgrade Weld to the version in the trunk? if yes, do you have any good hints?
ifischer
Haven't tackled that yet... I'll post in the Weld forum when I do:http://seamframework.org/Community/CDITimeoutResultsInAnNPE
Brian Leathem
FYI: A NonexistentConversationException is thrown in Weld 3.0.1-FINAL (bundled with glassfish 3.0.1).
Brian Leathem