【问题标题】:Primefaces Idle Monitor when multiple web pages are active in multiple Tab of BrowserPrimefaces Idle Monitor 当多个网页在浏览器的多个选项卡中处于活动状态时
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2019-01-15
    • 2010-12-18
    相关资源
    最近更新 更多