Hi to update in a db you need a transaction -> ejb Le 7 déc. 2012 06:36, "Howard W. Smith, Jr." <smithh032...@gmail.com> a écrit :
> That seemed to do the trick. I did the following: > > Added @PreDestroy to the following (previously-existing) method in my user > bean, which was called successfully by HttpSessionListener in > JSF-managed-bean webapp, when session timed out. > > @PreDestroy > public void sessionTimeout() { > > and then I just tested by the following in my web.xml > > <!-- session-timeout = 120 (2 hours) --> > <session-config> > <session-timeout> > 1 > </session-timeout> > </session-config> > > > I would like to update the database (user table via stateless session bean) > when session timeout, but that doesn't seem possible in JSF-managed-bean as > well as CDI-managed-bean. > > I think I can create a timer that does it immediately before session > timeout, but that may be a bit much or overkill or not the best solution. > :) > > Anyway, just wanted to followup on this topic. :) > > > On Thu, Dec 6, 2012 at 6:43 PM, Howard W. Smith, Jr. < > smithh032...@gmail.com > > wrote: > > > Romain, > > > > Since my TomEE/CDI-managed-bean web app is in production, as discussed > > earlier, I need this functionality. I never did write the code that I > > mentioned below, but I think I may need to try it out and see if it is a > > workaround since HttpSessionListener seems not useful in a TomEE (or > > OpenWebBeans) CDI-managed-bean app. > > > > Howard > > > > > > On Sun, Nov 25, 2012 at 2:35 AM, Howard W. Smith, Jr. < > > smithh032...@gmail.com> wrote: > > > >> Interesting. So, when server shutdown, sessions are not destroyed? > >> > >> If the answer is yes, I guess you are telling me that I should invoke > >> session.invalidate() in a @PreDestroy of my CDI @SessionScoped UserBean? > >> > >> I have a sessionTimeout method on my UserBean already, it is usually > >> called by HttpSessionListener on sessionDestroyed. > >> > >> > >> On Sun, Nov 25, 2012 at 2:27 AM, Romain Manni-Bucau < > >> rmannibu...@gmail.com> wrote: > >> > >>> Because the session is not destroyed, you need to destroy it or wait > the > >>> session timeout > >>> Le 25 nov. 2012 07:21, "Howard W. Smith, Jr." <smithh032...@gmail.com> > a > >>> écrit : > >>> > >>> > I have the following defined for my HttpSessionListener, and I don't > >>> see it > >>> > being executed (or showing up in server log) when I undeploy or > >>> shutdown > >>> > TomEE. > >>> > > >>> > /* > >>> > * To change this template, choose Tools | Templates > >>> > * and open the template in the editor. > >>> > */ > >>> > package pf; > >>> > > >>> > import java.util.Date; > >>> > > >>> > import javax.inject.Inject; > >>> > > >>> > import javax.servlet.annotation.WebListener; > >>> > import javax.servlet.http.HttpSessionEvent; > >>> > import javax.servlet.http.HttpSessionListener; > >>> > > >>> > import jsf.users.pf_UsersController; > >>> > > >>> > /** > >>> > * > >>> > * @author Administrator > >>> > */ > >>> > @WebListener > >>> > public class UserHttpSessionListener implements HttpSessionListener { > >>> > > >>> > @Inject > >>> > private pf_UsersController userBean; > >>> > > >>> > @Override > >>> > public void sessionCreated(HttpSessionEvent event) { > >>> > // Do here the job. > >>> > } > >>> > > >>> > @Override > >>> > public void sessionDestroyed(HttpSessionEvent event) { > >>> > /* > >>> > * JSF Managed Beans > >>> > * > >>> > pf_UsersController userBean = (pf_UsersController) > >>> > event.getSession(). > >>> > > >>> getAttribute("pf_usersController"); > >>> > */ > >>> > if (userBean != null && userBean.getUser() != null) { > >>> > String userName = userBean.getUser().getUserName(); > >>> > > >>> System.out.println("UserHttpSessionListener.sessionDestroyed(): > >>> > " + > >>> > userName + " session destroyed"); > >>> > userBean.sessionTimeout(); > >>> > } > >>> > } > >>> > > >>> > } > >>> > > >>> > >> > >> > > >