在我们的Web应用程序中,我们有一个baseTemplate.xhtml,我的应用程序的每个页面都使用这个模板。这个baseTemplate.xhtml具有处理空闲监视器的功能。
问题/问题:
如果用户打开多个选项卡并且一个选项卡处于活动状态但另一个选项卡处于空闲状态以获得指定的会话超时值,则该用户将被注销。
要求:
我想如果用户打开多个选项卡并且其中一个选项卡处于活动状态,则空闲监视器不应该注销。
<h:form>
<p:confirmDialog id="confirmDialog"
message="Please click Ok before the timer runs out: "
header="Are you there?"
severity="alert"
closable="false"
widgetVar="idleDialog">
<p:commandButton id="confirm"
value="Ok"
process="@this"
onclick="clearTimeout(window.logoffTimeoutId); PF('idleDialog').hide();"/>
</p:confirmDialog>
<p:remoteCommand name="terminateIdleSession"
actionListener="#{idleMonitorView.onIdle}"
process="@this"
out="count"/>
<p:idleMonitor timeout="#{5 * 60 * 1000}"
onidle="startTimer()"/>
</h:form>
<script type="text/javascript">
//<![CDATA[
function startTimer() {
clearTimeout(window.logoffUpdaterId);
PF('idleDialog').show();
// Set timeout to 2 minutes
var timeout = 2 * 60 * 1000;
// Calculate when the time runs out
window.logoffTime = new Date().getTime() + timeout;
// Start timer which calls remote command
window.logoffTimeoutId = setTimeout(terminateIdleSession, timeout);
// Update timer every second
window.logoffUpdaterId = setInterval(updateTimer, 1000);
// Update timer now
updateTimer();
}
// Update the timer
function updateTimer() {
var seconds = Math.ceil((window.logoffTime - new Date().getTime()) / 1000);
$("#logoffTimeout").html(seconds);
}
// Create span to contain the timer
$(function(){
$("#myForm\\:confirmDialog .ui-confirm-dialog-message").append("<span id=logoffTimeout/>");
});
//]]>
</script>
答案 0 :(得分:4)
有点晚了,但我希望它对某人有用。 Primefaces的idleMonitor
现在具有一个multiWindowSupport
属性,因此您最终会得到如下所示:
<p:idleMonitor timeout="5000" multiWindowSupport="true" onidle="PF('idleDialog').show()" />