I am trying to handle the session timeout via idlemonitor, a primefaces component.
I am doing this because i need to let the user know that due to inactivity the se
I've found a solution that works pretty nice, and i don't have to deal with the NPE.
Following scenario:
If the user is idle for more than 6 sec, the session is invalidated through ajax, no user interaction required. That means, even if the user is idle for more than 20 minutes, the session is already invalid and I don't have to deal with the NPE.
After 6 seconds a dialog(through javascript alert) is generated and lets the user know that he was inactive for a certain amount of time and the session has expired. After the dialog is closed, the user is redirected to the login page.
By the way, i used 6 seconds just for testing purposes. My default settings are:
This solution matches exactly to my requirements.
Code for idlemonitor:
<!-- language: lang-xml -->
<p:idleMonitor timeout="1800000" >
<p:ajax event="idle" listener="#{loginController.timeout()}" oncomplete="alert('Session expired etc.')"/>
</p:idleMonitor>
Code for loginController.timeout():
public void timeout() throws IOException {
FacesContext.getCurrentInstance().getExternalContext()
.invalidateSession();
FacesContext.getCurrentInstance().getExternalContext()
.redirect("...loginpage.xhtml");
}