5 Replies Latest reply on Aug 12, 2010 3:03 PM by wangliyu

    Scoped Contexts lifecycle gotcha

    wangliyu
      Hope this is helpful:
      1 >Weld init Request & Dependent context in ServletListener.requestInitialized() and destroy them in Servlet.requestDestroyed() method. so they are the first 2 context create and always be there in the whole life of request (before JSF servlet)

      2 >Session Context will be init at JSF beforeRestoreView phase event of the first Get Request, the only way to kill the session is calling HttpSession.invalidate(); before that you have to call Conversation.end() if there is a long run conversation (seems a bug of Weld)

      3> Conversation Context will be init everytime at JSF beforeRestoreView phase event(if there is no long-running conversation), otherwise the previous conversation will be restored at that event.

      4> By default ended conversation will be cleanup at afterRenderResponse event (normal post request) or after response complete (Redirect case).

      Important note:
         the ended conversation will be cleanup only if the current Session is available, if you called session.invalid(), this cleanup() will be skipped and you will get Exception after that (Conversation context stored in the Session is already gone but the cid is still available.) in the restore conversation step.

      Detail see:

      http://seamframework.org/Community/ExceptionWhenEndingConversationWithPostRedirectGet

      and

      http://seamframework.org/Community/PostredirectAndRestartConversationWithOneClick