Getting SessionScoped bean from HttpSessionListener?

不问归期 提交于 2019-12-01 12:36:59

This code should work fine. Note that the FacesContext isn't necessarily available there since there's not necessarily means of a HTTP request in the thread running at that point, but you already outcommented that. Are you sure that you was actually running the code as shown in the question? Clean, rebuild, redeploy, etc.

An alternative is to let your UserSessionBean implement HttpSessionBindingListener and then do the job in the valueUnbound() method.

@ManagedBean
@SessionScoped
public class UserSessionBean implements HttpSessionBindingListener {

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        for (File file : files) {
            file.delete();
        }
    }

    // ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!