Primefaces 空闲监视器,当多个网页在浏览器的多个选项卡中处于活动状态时



在我们的Web应用程序中,我们有一个baseTemplate.xhtml我的应用程序的每个页面都使用此模板。此基本模板.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>

有点晚了,但我希望它对某人有用。Primefaces的idleMonitor现在有一个multiWindowSupport属性,所以你最终会得到这样的东西:

<p:idleMonitor timeout="5000" multiWindowSupport="true" onidle="PF('idleDialog').show()" />

相关内容

最新更新