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>
package org.primefaces.showcase.view.misc;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
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"));
}
}