Hey guys. I\'m trying to get a session bean in a HttpSessionListener so that when the user logs out or the session expires I can delete some files that the user created in
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();
}
}
// ...
}