ICEFaces 会话自动扩展

发布于 2024-07-16 12:25:51 字数 171 浏览 8 评论 0原文

我有一个应用程序,用户经常让页面整天在浏览器中运行。 该页面有一个间隔渲染,每 30 秒更新一次数据。

但是,如果用户有一段时间没有与页面交互,它仍然会过期。 我希望它能够在浏览器打开并发出预定请求时自动扩展。

有没有一种方法可以在每次为这些页面之一触发预定渲染器时自动延长会话?

I have an application in which users frequently leave the page running in their browser all day. The page has an intervalrendered that updates data every 30 seconds.

However, if the user doesn't interact with the page for a while, it still expires. I'd like it to auto-extend for as long as the browser is open and making the scheduled requests.

Is there a way to automatically extend the session everytime that the scheduled renderer is fired for one of these pages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

少女的英雄梦 2024-07-23 12:25:51

当 ICEFaces 每 30 秒调用一次我的代码时,我真的不想通过 Javascript hack 来单击按钮。 以下针对 ICEFaces 内部计时器的黑客解决方法似乎有效:

  private void updateSessionExpiration () {
      HttpSession sess = getSession();
      if (sess != null) {
        try {
            Field fld = SessionDispatcher.class.getDeclaredField("SessionMonitors");
            fld.setAccessible(true);
            Map map = (Map)fld.get(null);
            String sessID = sess.getId();
            if (map.containsKey(sessID)) {
                log.info("About to touch session...");
                SessionDispatcher.Monitor mon = 
                     (SessionDispatcher.Monitor)map.get(sessID);
                mon.touchSession();
            }
        } catch (Exception e) {
            log.error("Failed to touch session");
        }
      }
  }

此外,使用 ICEFaces 1.8.2RC1(大概最终也会发布 ICEFaces 1.8.2 的发行版本),有两种新的解决方法可用:

HttpServletRequest request = (HttpServletRequest) servletRequest; 
HttpSession session = request.getSession(); 
if (session != null) { 
    SessionDispatcher.Monitor.lookupSessionMonitor(session).touchSession(); 
} 

或者,将其放入 web.xml 中以更新对其中 URL 的任何点击一个特定的模式:

<filter> 
    <filter-name>Touch Session</filter-name> 
    <filter-class>com.icesoft.faces.webapp.http.servlet.TouchSessionFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>Touch Session</filter-name> 
    <url-pattern>/seam/remoting/*</url-pattern> 
</filter-mapping> 

I don't really want to do Javascript hacks to click buttons when my code is already being called every 30 seconds by ICEFaces. The following hacked workaround for ICEFaces internal timer seems to work:

  private void updateSessionExpiration () {
      HttpSession sess = getSession();
      if (sess != null) {
        try {
            Field fld = SessionDispatcher.class.getDeclaredField("SessionMonitors");
            fld.setAccessible(true);
            Map map = (Map)fld.get(null);
            String sessID = sess.getId();
            if (map.containsKey(sessID)) {
                log.info("About to touch session...");
                SessionDispatcher.Monitor mon = 
                     (SessionDispatcher.Monitor)map.get(sessID);
                mon.touchSession();
            }
        } catch (Exception e) {
            log.error("Failed to touch session");
        }
      }
  }

Also, with ICEFaces 1.8.2RC1 (and presumably eventually with the release version of ICEFaces 1.8.2 as well), there are two new workarounds available:

HttpServletRequest request = (HttpServletRequest) servletRequest; 
HttpSession session = request.getSession(); 
if (session != null) { 
    SessionDispatcher.Monitor.lookupSessionMonitor(session).touchSession(); 
} 

Or, put this in the web.xml to update on any hit to URLs within a specific pattern:

<filter> 
    <filter-name>Touch Session</filter-name> 
    <filter-class>com.icesoft.faces.webapp.http.servlet.TouchSessionFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>Touch Session</filter-name> 
    <url-pattern>/seam/remoting/*</url-pattern> 
</filter-mapping> 
情绪 2024-07-23 12:25:51

ICEfaces 有一个保持会话活动的内部机制(该机制有时称为“心跳”)。 您可以查看相关的文档并配置web.xml 中提到的参数(尤其是 heartbeatIntervalheartbeatTimeout)。

ICEfaces has an internal mechanism for keeping sessions alive (the mechanism is sometimes referred to as "heartbeating"). You may have a look at the belonging documentation and configure the mentioned parameters (especially heartbeatInterval and heartbeatTimeout) in your web.xml.

贱贱哒 2024-07-23 12:25:51

Iceface 的 Ajax 桥具有回调 API,例如您可以使用的 Ice.onSessionExpired()

<body id="document:body">
    <script type="text/javascript">
        Ice.onSessionExpired('document:body', function() {
            <!-- Do something here -->
        });
    </script>

请参阅http://www.icefaces.org/docs/v1_8_0 /htmlguide/devguide/references4.html#1094786 了解更多详细信息。

Iceface's Ajax bridge has callback APIs, for example Ice.onSessionExpired() which you may be able to use.

<body id="document:body">
    <script type="text/javascript">
        Ice.onSessionExpired('document:body', function() {
            <!-- Do something here -->
        });
    </script>

See http://www.icefaces.org/docs/v1_8_0/htmlguide/devguide/references4.html#1094786 for more details.

Hello爱情风 2024-07-23 12:25:51

如果我不明白你的真正目的是什么,那么你需要一种计时器,它可以自动扩展每个用户会话客户端,从而覆盖服务器端默认页面会话过期时间(通常为 30 分钟,仅提供详细信息,因为我了解该脚本如果用户在页面上处于活动状态,则每 30 秒“呈现”一次)。

如果是这样的话,在 JSF 之前,我总是通过地下 Javascript 扩展非活动用户会话,所以我也会在您的情况下使用它。 实际上,您可以在 Javascript 中构建一个简单的页面侦听器,从以下位置开始:

window.setInterval( expression , msecIntervalTiming );

“表达式”可以是一个被调用函数,您可以在其中调用一些虚拟 JSF,以保持会话处于活动状态,而无需重新加载用户访问的当前页面,过去我使用过标准框架或 iframe 进行 http 调用,现在使用 XHR / Ajax 也更简单。

Javascript 示例:

var timerID = null;
function simplePageListener() { // invoked by some user event denoting his absence status
    // here goes all events and logic you need and know for firing the poller...
    if (timerID == null) // avoid  duplicates
        timerID = window.setInterval( "window.startPoller()", msecIntervalTiming );
}
//...
function pollerStart() {
  // make iframe or ajax/xhr requests
}
function pollerStop() {
  // make action like page reloading or other needings
}
//...
function triggeredCleanTimer(timer) { // invoked by some user event denoting his active status
  clearTimeout(timer); // it can be also the global variable "timerID"
  timerID = null;
}

基本上,您使用“timerID”作为全局引用来跟踪侦听器状态,因此当您需要激活“自动扩展”时,您可以为其分配一个 setInterval。 相反,当用户返回页面(由您知道的某些事件触发)时,您可以清除停止侦听器轮询的超时。 上面的示例显然意味着用户返回时必须手动重新加载页面

但是,在您的具体情况下,我将避免干扰 Icefaces 框架自动生成的 JavaScript。 即使对于 ipothesys,您可以定期模拟不可见输入元素上的一些用户事件(样式设置为“visibility:hidden”,绝对不在“display:none”),这会导致 Icefaces 事件不停止它并使其持续工作

> 您可以定期调用它来调用单击事件有关

 document.forms["YourDummyForm"]["invisivleButton"].click();

用法,请参阅 Devedge Online 的旧版伟大 JS 文档:-)

http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/window.html#1203669

If I have undestood what is your real purpose, then you need a sort of timer which automatically extends every user session client side, consequentely overriding the server side default page session expiration timing ( usually 30 minutes, only for detail because I understood that the script "renders" every 30 seconds if the user is active on the page ).

If so well, before JSF I always extended inactive user sessions via underground Javascript, so I'll use it also in your case. Pratically you can build a simple page listener in Javascript starting from:

window.setInterval( expression , msecIntervalTiming );

the "expression" can be a called function in which you invoke some dummy JSF needed to keep the session alive without reloading the current page visited by the user, in the past I used standard frame or iframe to make http calls, now with XHR / Ajax is more simple too.

Javascript example:

var timerID = null;
function simplePageListener() { // invoked by some user event denoting his absence status
    // here goes all events and logic you need and know for firing the poller...
    if (timerID == null) // avoid  duplicates
        timerID = window.setInterval( "window.startPoller()", msecIntervalTiming );
}
//...
function pollerStart() {
  // make iframe or ajax/xhr requests
}
function pollerStop() {
  // make action like page reloading or other needings
}
//...
function triggeredCleanTimer(timer) { // invoked by some user event denoting his active status
  clearTimeout(timer); // it can be also the global variable "timerID"
  timerID = null;
}

Substantially you use the "timerID" as a global reference to keep track of the listener status, so when you need to activate the "autoextension" you assign it a setInterval. Instead when the user come back to the page (triggered by some event you know), you clear the timeout stopping the listener polling. The above example obviously implies that the user, when comes back, must reload the page manually.

However in your specifical case, I'll avoid to interfere with javascript automatically generated by Icefaces framework. Even if, for ipothesys, you could simulate periodically some user events on invisible input elements (style set on "visibility: hidden", absolutely not on "display: none"), this causes the Icefaces event to not stop it and making itself work continuosly

Elements like <input type="button" name="invisivleButton" value="..." style="visibility: hidden, z-index: 0;" /> on which you can call periodically invoke the click event by

 document.forms["YourDummyForm"]["invisivleButton"].click();

For the usage, see the old great JS docs of Devedge Online :-)

http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/window.html#1203669

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文