IdleMonitor tracks user actions and invokes corresponding events when user goes idle after a specified time and becomes active again.
<div class="card">
<h:form>
Stay idle on this page for 5 seconds to view the demo.
<p:growl id="messages" showDetail="true" sticky="true"/>
<p:idleMonitor timeout="5000">
<p:ajax event="idle" listener="#{idleMonitorView.onIdle}" update="messages"/>
<p:ajax event="active" listener="#{idleMonitorView.onActive}" update="messages"/>
</p:idleMonitor>
</h:form>
</div>
@Named
@RequestScoped
public class IdleMonitorView {
public void onIdle() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
"No activity.", "User is idle"));
}
public void onActive() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
"Activity detected", "User is active"));
}
}