【发布时间】:2017-11-19 02:19:51
【问题描述】:
在我们的 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>
【问题讨论】:
-
使用stackoverflow.com/questions/7389328/… 启动/停止其他空闲监视器(如果它们没有焦点)。也许您需要重新启动/重置它们。最后,客户端都只是 html/css/javascript
-
我刚刚添加了源代码,请你帮我修复它,我不擅长java脚本
标签: session jsf primefaces