tags:

views:

641

answers:

3

Hi

I am playing around with a little seam app that has session scope. The last method is sending as mail. How can I invalidate my session after having the mail sent? Right now, when the user calls the initial url again, the session still lives and all of the previously filled in form data is still there.

I have found examples how to do that with conversations and ejb, but not with POJOs and sessions.

Thanks, Rory

+1  A: 

Session.instance().invalidate();

01
A: 

Thanks, that works!

Next, related question:

I send the mail: renderer.render("/mail.xhtml"); return "success"; and inform the user about successful mailsending. Only after that, I'd like to invalidate the session. How?

Thanks, Rory

+3  A: 

Per ISASI's answer you can use this code to invalidate the session:

Session.instance().invalidate();

In answer to your follow up "question" (which you added as an answer, bizarrely). To close the session after informing the user of the sucess then you create a "confirm" page and redirect to it based on a rule associated with the "success" outcome. Then create a page action to invalidate the session.

<page view-id="/process/confirm.xhtml" action="#{emailManager.completeSession}">

Technically, the session will be closed beofre rendering the page, so that may create a timing issue with regards accessing session data, so you may need to hack around with page parameters to compensate. This is because you are basically doing it "wrong" by using a session per email. You'll be much better off using a conversation because there is an @End annotation that ends the conversation after rendering the view - much easier.

You'll need to switch to using conversations once your application involves more than one task as any state held between tasks will be lost. I imagine that will happen quite quickly. These timing and state management issues are the problem Seam conversations was designed to solve.

Simon Gibbs