Listening to when the user session is ended in a JSF managed bean2019 Community Moderator ElectionIs there any in JSF2 a callback for activation / deactivation of a session bean?JSF store UserData before Session Invalidate or LogoutJSF Login Two users at the same timeHow to invalidate session in JSF 2.0?JSF Session management and tunningBatching writes to the DB in JSF session scope & writing at the end of user session. Is this approach correct?User Session Management in Restful Web Services in session shared clustered environmentPassing session between jsf backing bean and modelJSF Catch Session TimeoutJSF logout other users while maintaining my active session.Using a HttpServlet Session Attribute in JSFDoes JSF store UIComponents in session?Corruption of a variable in a session bean using JSF/Spring

Is there a place to find the pricing for things not mentioned in the PHB? (non-magical)

Could the Saturn V actually have launched astronauts around Venus?

What's the meaning of a knight fighting a snail in medieval book illustrations?

Custom alignment for GeoMarkers

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

As a new Ubuntu desktop 18.04 LTS user, do I need to use ufw for a firewall or is iptables sufficient?

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

How to make healing in an exploration game interesting

While on vacation my taxi took a longer route, possibly to scam me out of money. How can I deal with this?

When to use a slotted vs. solid turner?

Math equation in non italic font

What is the adequate fee for a reveal operation?

Why do newer 737s use two different styles of split winglets?

Why is the President allowed to veto a cancellation of emergency powers?

Adventure Game (text based) in C++

Print a physical multiplication table

Do I need to be arrogant to get ahead?

What options are left, if Britain cannot decide?

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Does .bashrc contain syntax errors?

I got the following comment from a reputed math journal. What does it mean?

Knife as defense against stray dogs

If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?



Listening to when the user session is ended in a JSF managed bean



2019 Community Moderator ElectionIs there any in JSF2 a callback for activation / deactivation of a session bean?JSF store UserData before Session Invalidate or LogoutJSF Login Two users at the same timeHow to invalidate session in JSF 2.0?JSF Session management and tunningBatching writes to the DB in JSF session scope & writing at the end of user session. Is this approach correct?User Session Management in Restful Web Services in session shared clustered environmentPassing session between jsf backing bean and modelJSF Catch Session TimeoutJSF logout other users while maintaining my active session.Using a HttpServlet Session Attribute in JSFDoes JSF store UIComponents in session?Corruption of a variable in a session bean using JSF/Spring










5















Is it possible to do something like this: When a user session starts I read a certain integral attribute from the database. As the user performs certain activities in this session, I update that variable(stored in session) & when the session ends, then I finally store that value to the DB.



My question is how do I identify using the JSF framework if the user session has ended & I should then store the value back to DB?










share|improve this question




























    5















    Is it possible to do something like this: When a user session starts I read a certain integral attribute from the database. As the user performs certain activities in this session, I update that variable(stored in session) & when the session ends, then I finally store that value to the DB.



    My question is how do I identify using the JSF framework if the user session has ended & I should then store the value back to DB?










    share|improve this question


























      5












      5








      5


      1






      Is it possible to do something like this: When a user session starts I read a certain integral attribute from the database. As the user performs certain activities in this session, I update that variable(stored in session) & when the session ends, then I finally store that value to the DB.



      My question is how do I identify using the JSF framework if the user session has ended & I should then store the value back to DB?










      share|improve this question
















      Is it possible to do something like this: When a user session starts I read a certain integral attribute from the database. As the user performs certain activities in this session, I update that variable(stored in session) & when the session ends, then I finally store that value to the DB.



      My question is how do I identify using the JSF framework if the user session has ended & I should then store the value back to DB?







      session jsf listener managed-bean






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 19 '16 at 13:50









      BalusC

      855k30031673233




      855k30031673233










      asked Jun 5 '11 at 5:50









      Rajat GuptaRajat Gupta

      10.8k48149266




      10.8k48149266






















          3 Answers
          3






          active

          oldest

          votes


















          9














          Apart from the HttpSessionListener, you can use a session scoped managed bean for this. You use @PostConstruct (or just the bean's constructor) and @PreDestroy annotations to hook on session creation and destroy



          @ManagedBean
          @SessionScoped
          public class SessionManager

          @PostConstruct
          public void sessionInitialized()
          // ...


          @PreDestroy
          public void sessionDestroyed()
          // ...





          The only requirement is that this bean is referenced in a JSF page or as @ManagedProperty of any request scoped bean. Otherwise it won't get created. But in your case this should be no problem as you're apparently already using a session scoped managed bean, just adding a @PreDestroy method ought to be sufficient.






          share|improve this answer

























          • I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

            – Bill Rosmus
            Aug 7 '12 at 2:05











          • mkyong.com/servlet/…

            – Mahdi Esmaeili
            Dec 12 '18 at 11:39


















          5















          My question is how do I identify using
          the JSF framework if the user session
          has ended & I should then store the
          value back to DB?




          The JSF framework does not have a separate concept of a session; it uses the underlying session management features of the Servlet specification.



          You would have to create a HttpSessionListener that provides hooks for you to capture the session creation and destruction events, where you can read the value and store it back into the DB.






          share|improve this answer






























            2














            HttpSessionListener, or if you need Dependency Injection for that save, you might use @PostConstruct & @PreDestroy. Remember that the session is destroyed when you call invalidate() or after session timeout, not when the user closes the browser. Why do you use Session Scope anyway, Conversation Scope might fit you better.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6241249%2flistening-to-when-the-user-session-is-ended-in-a-jsf-managed-bean%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              9














              Apart from the HttpSessionListener, you can use a session scoped managed bean for this. You use @PostConstruct (or just the bean's constructor) and @PreDestroy annotations to hook on session creation and destroy



              @ManagedBean
              @SessionScoped
              public class SessionManager

              @PostConstruct
              public void sessionInitialized()
              // ...


              @PreDestroy
              public void sessionDestroyed()
              // ...





              The only requirement is that this bean is referenced in a JSF page or as @ManagedProperty of any request scoped bean. Otherwise it won't get created. But in your case this should be no problem as you're apparently already using a session scoped managed bean, just adding a @PreDestroy method ought to be sufficient.






              share|improve this answer

























              • I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

                – Bill Rosmus
                Aug 7 '12 at 2:05











              • mkyong.com/servlet/…

                – Mahdi Esmaeili
                Dec 12 '18 at 11:39















              9














              Apart from the HttpSessionListener, you can use a session scoped managed bean for this. You use @PostConstruct (or just the bean's constructor) and @PreDestroy annotations to hook on session creation and destroy



              @ManagedBean
              @SessionScoped
              public class SessionManager

              @PostConstruct
              public void sessionInitialized()
              // ...


              @PreDestroy
              public void sessionDestroyed()
              // ...





              The only requirement is that this bean is referenced in a JSF page or as @ManagedProperty of any request scoped bean. Otherwise it won't get created. But in your case this should be no problem as you're apparently already using a session scoped managed bean, just adding a @PreDestroy method ought to be sufficient.






              share|improve this answer

























              • I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

                – Bill Rosmus
                Aug 7 '12 at 2:05











              • mkyong.com/servlet/…

                – Mahdi Esmaeili
                Dec 12 '18 at 11:39













              9












              9








              9







              Apart from the HttpSessionListener, you can use a session scoped managed bean for this. You use @PostConstruct (or just the bean's constructor) and @PreDestroy annotations to hook on session creation and destroy



              @ManagedBean
              @SessionScoped
              public class SessionManager

              @PostConstruct
              public void sessionInitialized()
              // ...


              @PreDestroy
              public void sessionDestroyed()
              // ...





              The only requirement is that this bean is referenced in a JSF page or as @ManagedProperty of any request scoped bean. Otherwise it won't get created. But in your case this should be no problem as you're apparently already using a session scoped managed bean, just adding a @PreDestroy method ought to be sufficient.






              share|improve this answer















              Apart from the HttpSessionListener, you can use a session scoped managed bean for this. You use @PostConstruct (or just the bean's constructor) and @PreDestroy annotations to hook on session creation and destroy



              @ManagedBean
              @SessionScoped
              public class SessionManager

              @PostConstruct
              public void sessionInitialized()
              // ...


              @PreDestroy
              public void sessionDestroyed()
              // ...





              The only requirement is that this bean is referenced in a JSF page or as @ManagedProperty of any request scoped bean. Otherwise it won't get created. But in your case this should be no problem as you're apparently already using a session scoped managed bean, just adding a @PreDestroy method ought to be sufficient.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 5 '11 at 11:34

























              answered Jun 5 '11 at 11:14









              BalusCBalusC

              855k30031673233




              855k30031673233












              • I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

                – Bill Rosmus
                Aug 7 '12 at 2:05











              • mkyong.com/servlet/…

                – Mahdi Esmaeili
                Dec 12 '18 at 11:39

















              • I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

                – Bill Rosmus
                Aug 7 '12 at 2:05











              • mkyong.com/servlet/…

                – Mahdi Esmaeili
                Dec 12 '18 at 11:39
















              I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

              – Bill Rosmus
              Aug 7 '12 at 2:05





              I am trying this second approach as it looks good. Plus I need to be able to get a handle on ejbs and entity manager which seems to only be available from managed beans in JSF (as opposed to the HttpSessionListener). I make the sessionscoped managedbean a managedproperty of my login handling requestscoped bean so that it comes into scope when the user logs in. The problem I'm having is that it seems the method I marked @PreDestroy gets called as the login bean goes out of scope (i.e. when the login method returns). So my code is firing early. Any ideas on why this might happen?

              – Bill Rosmus
              Aug 7 '12 at 2:05













              mkyong.com/servlet/…

              – Mahdi Esmaeili
              Dec 12 '18 at 11:39





              mkyong.com/servlet/…

              – Mahdi Esmaeili
              Dec 12 '18 at 11:39













              5















              My question is how do I identify using
              the JSF framework if the user session
              has ended & I should then store the
              value back to DB?




              The JSF framework does not have a separate concept of a session; it uses the underlying session management features of the Servlet specification.



              You would have to create a HttpSessionListener that provides hooks for you to capture the session creation and destruction events, where you can read the value and store it back into the DB.






              share|improve this answer



























                5















                My question is how do I identify using
                the JSF framework if the user session
                has ended & I should then store the
                value back to DB?




                The JSF framework does not have a separate concept of a session; it uses the underlying session management features of the Servlet specification.



                You would have to create a HttpSessionListener that provides hooks for you to capture the session creation and destruction events, where you can read the value and store it back into the DB.






                share|improve this answer

























                  5












                  5








                  5








                  My question is how do I identify using
                  the JSF framework if the user session
                  has ended & I should then store the
                  value back to DB?




                  The JSF framework does not have a separate concept of a session; it uses the underlying session management features of the Servlet specification.



                  You would have to create a HttpSessionListener that provides hooks for you to capture the session creation and destruction events, where you can read the value and store it back into the DB.






                  share|improve this answer














                  My question is how do I identify using
                  the JSF framework if the user session
                  has ended & I should then store the
                  value back to DB?




                  The JSF framework does not have a separate concept of a session; it uses the underlying session management features of the Servlet specification.



                  You would have to create a HttpSessionListener that provides hooks for you to capture the session creation and destruction events, where you can read the value and store it back into the DB.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 5 '11 at 6:18









                  Vineet ReynoldsVineet Reynolds

                  66.3k16131169




                  66.3k16131169





















                      2














                      HttpSessionListener, or if you need Dependency Injection for that save, you might use @PostConstruct & @PreDestroy. Remember that the session is destroyed when you call invalidate() or after session timeout, not when the user closes the browser. Why do you use Session Scope anyway, Conversation Scope might fit you better.






                      share|improve this answer



























                        2














                        HttpSessionListener, or if you need Dependency Injection for that save, you might use @PostConstruct & @PreDestroy. Remember that the session is destroyed when you call invalidate() or after session timeout, not when the user closes the browser. Why do you use Session Scope anyway, Conversation Scope might fit you better.






                        share|improve this answer

























                          2












                          2








                          2







                          HttpSessionListener, or if you need Dependency Injection for that save, you might use @PostConstruct & @PreDestroy. Remember that the session is destroyed when you call invalidate() or after session timeout, not when the user closes the browser. Why do you use Session Scope anyway, Conversation Scope might fit you better.






                          share|improve this answer













                          HttpSessionListener, or if you need Dependency Injection for that save, you might use @PostConstruct & @PreDestroy. Remember that the session is destroyed when you call invalidate() or after session timeout, not when the user closes the browser. Why do you use Session Scope anyway, Conversation Scope might fit you better.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 5 '11 at 12:33









                          Cosmin CosminCosmin Cosmin

                          1,05911333




                          1,05911333



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6241249%2flistening-to-when-the-user-session-is-ended-in-a-jsf-managed-bean%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme