6 Replies Latest reply on May 1, 2009 5:00 AM by Nikolay Elenkov

    Destroy all beans etc from session.

    ioannis ntantis Newbie

      Hi all,

      I was wondering, is there some way that someone can delete everything from the session?

      For example: In a web application, when a user clicks on the home button, i want to delete all of the context that was created for him/her (session beans etc).

      Any help is appreciated.


        • 1. Re: Destroy all beans etc from session.
          Gregory Nikle Apprentice

          I follow your question and add mine. Is possible to check, that everythink any references/etc was completly cleaned from session to clean by GC?

          • 2. Re: Destroy all beans etc from session.
            ioannis ntantis Newbie

            hahahah join the club my friend, i think it would be really usefull if this could be done. I am pretty sure it ll be possible but i just cant figure out how. I am searching for it right now, if i find anything i will update asap.


            • 3. Re: Destroy all beans etc from session.
              Nikos Paraskevopoulos Novice

              Hi Gianni,

              There is allways the servlet API (HttpSession.getAttributeNames() and HttpSession.removeAttribute(String name)) that you can use. For a more advanced way:

              Session EJBs may (required by SEAM I think) have removal methods, annotated with @Remove. Calling this method will remove the instance from the container (EJB 3 specs, par.4.3.11).

              SEAM implements the observer pattern, see docs par.6.9. So if you configure your @Remove methods to also be @Observers of a specific event, raised from a page action when your home page loads, this would effectively remove them.


              // in every component that you want removed
              public class MySessionComponent {
                public void remove() {

              And in the home page action:

              public void homePageAction() {

              • 4. Re: Destroy all beans etc from session.
                ioannis ntantis Newbie

                Hi niko,

                As i am at work now i dont have time to implement and provide my results. But thanks a lot of your help this should help a lot.

                Thanks, Eyxaristo,

                • 5. Re: Destroy all beans etc from session.
                  Arbi Sookazian Master

                  In a generic sense here is how to invalidate a session from Faces:

                  ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
                  HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
                  HttpSession session = (HttpSession)ectx.getSession(false);

                  Then you need to spawn a new HttpSession but I'm not familiar with how to do this programmatically in the context of a Seam app.  This would typically involve authentication and authorization of course.

                  In case you're not interested in Session invalidation, but rather destroying all LRCs (or demoting them all to temporary conversations).  If that's the case, then something like this may do the trick...


                  Seam maintains a list of all long-running conversations and metadata about each one
                  in the built-in Seam component named conversationEntries. These conversations
                  are exported to the session-scoped context variable conversationList as a list of
                  ConversationEntry objects, whose properties are shown in table 7.7. This list
                  excludes all entries that aren’t displayable by default. You can use the conversation-
                  Entries component to export a custom list.


                  <page view-id="/home.xhtml" >
                            <action execute="#{foo.cleanup}"/>          

                  public class Foo{
                     public void cleanup(){
                         //code loops thru list of ConversationEntry objects and invokes destroy() method on each instance.

                  NOTE: I haven't actually tested this and there may be a better standard way of solving this problem...

                  • 6. Re: Destroy all beans etc from session.
                    Nikolay Elenkov Master

                    If you really want to delete everything, just invalidate the session:


                    You shouldn't invalidate the HttpSession directly, because Seam stores all kind of
                    stuff in there, hence the need to call a Seam API. The call above schedule's the
                    session for invalidation, actual work is done at the end of the request.