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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Brian Leathem
  • 4,609
  • 1
  • 24
  • 44

2 Answers2

2

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
  • 4,609
  • 1
  • 24
  • 44
  • 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! – Wolkenarchitekt Jun 10 '10 at 15:43
  • Did you already manage to upgrade Weld to the version in the trunk? if yes, do you have any good hints? – Wolkenarchitekt Jun 10 '10 at 16:15
  • Haven't tackled that yet... I'll post in the Weld forum when I do: http://seamframework.org/Community/CDITimeoutResultsInAnNPE – Brian Leathem Jun 11 '10 at 01:39
  • FYI: A NonexistentConversationException is thrown in Weld 3.0.1-FINAL (bundled with glassfish 3.0.1). – Brian Leathem Jun 22 '10 at 20:02
0

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.

Community
  • 1
  • 1
Wolkenarchitekt
  • 20,170
  • 29
  • 111
  • 174
  • Thanks for the feedback, but that's kind of the opposite of what I was hoping to achieve. I wanted to use an `` to "escape" a currently long running conversation. This should work according to the spec, see the answer I posted. – Brian Leathem Jun 10 '10 at 14:55