I would like to send user to /login.xhtml
if he/she is idle for a given period of time. I have tried PrimeFaces <p:idlemonitor>
but can't figure out how to achieve this.
Asked
Active
Viewed 946 times
3

Jasper de Vries
- 19,370
- 6
- 64
- 102
-
I don't know if you are looking to that in specific way but I can tell you how to do it with JavaScript and jQuery – Iman Mohamadi May 04 '14 at 08:53
-
Iman Mohamadi you can go ahead – May 04 '14 at 09:15
3 Answers
2
Use the IdleMonitor
component <p:idleMonitor>
<p:idleMonitor timeout="3000">
<p:ajax event="idle" listener="#{idleMonitorBean.processTimeOut()}"/>
</p:idleMonitor>
Note: timeout
in millseconds
Then in your listener method just specify the redirect()
path.
@Model
public class IdleMonitorBean {
public void processTimeOut() throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect(
"/contextroot/index.xhtml");
}
}

Paul Samsotha
- 205,037
- 37
- 486
- 720
0
You can watch for user activities such as clicks (maybe you consider mouse move or scroll as not idle, totally depends on you).
var resetActivityTimer = function () {
if (typeof window.userActivity != 'undefined')
clearTimeout(window.userActivity);
window.userActivity = setTimeout(function () {
window.location.href = 'login.xhtml';
//number of ms until to be considered idle
}, 30000);
};
$(window).click(function () {
//if user clicked they are not idle
resetActivityTimer();
});
//initialize timer
resetActivityTimer();
Note, If you want to consider scroll or mouse moves as activity don't forget to throttle the events.

Jasper de Vries
- 19,370
- 6
- 64
- 102

Iman Mohamadi
- 6,552
- 3
- 34
- 33
0
I'd prefer to keep things client side in this situation. PrimeFaces Extensions pe:javascript
can help out here. For example:
<p:idleMonitor timeout="...">
<pe:javascript event="idle"
execute="top.location.href='#{request.contextPath}/login.xhtml'"/>
</p:idleMonitor>

Jasper de Vries
- 19,370
- 6
- 64
- 102