In my web application I have a idle monitor which is triggered if a user is idle for 5 minutes. It will open a confirm dialog which will wait for 2 minutes; after that it will redirect to login page.
Requirement: I want to show a countdown timer with the time remaining before the user will be redirected to the login page.
baseTemplate.xhtml:
<h:form>
<p:idleMonitor timeout="#{idleMonitorView.timeoutVal}"
onidle="startTimer()" />
<p:confirmDialog id="confirmDialog"
message="You have been idle, Please click ok to remain logged in"
header="Are you there?" severity="alert" widgetVar="idleDialog">
<p:commandButton id="confirm" value="Ok" oncomplete="extendSession()" />
</p:confirmDialog>
<p:remoteCommand name="terminateIdleSession" actionListener="#{idleMonitorView.onIdle}" out="count" />
<script type="text/javascript">
var extend_session = 0;
function startTimer() {
extend_session = 0;
setTimeout("timeout()", 120000);
PF('idleDialog').show();
}
function timeout() {
if (extend_session == 0) {
terminateIdleSession();
}
}
function extendSession() {
extend_session = 1;
PF('idleDialog').hide();
}
</script>
</h:form>
Problem: I don't know that how to achieve this requirement.