2009-04-10 64 views
1

我有一个应用程序,用户经常在整个浏览器中运行整个页面。该页面有一个intervalrender,每30秒更新一次数据。ICEFaces会话自动扩展

但是,如果用户暂时不与页面交互,它仍然会过期。只要浏览器处于打开状态并提供预定的请求,我希望它自动扩展。

有没有一种方法可以在每次为其中一个页面触发预定渲染器时自动扩展会话?

回答

0

如果我已经undestood什么是你真正的目的,那么你需要一种计时器自动延长每个用户会话的客户端,consequentely覆盖服务器端的默认页面会话过期时间(通常为30分钟,仅细节,因为我如果用户在页面上处于活动状态,则该脚本会每30秒“呈现”一次)。

如果这么好,在JSF之前,我总是通过地下Javascript扩展非活动用户会话,所以我会在你的情况下使用它。 Pratically你可以建立在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”作为全球基准跟踪的侦听器的状态,所以当你需要激活“autoextension”你为它分配的setInterval。相反,当用户回到页面(由您所知的某个事件触发)时,您可以清除停止侦听器轮询的超时。 上面的例子显然意味着用户返回时必须手动重新加载页面

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

像<这样的元素input type =“button”name =“invisivleButton”value =“...”style =“visibility:hidden,z-index:0;”/>上,你可以调用定期

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

调用Click事件的用法,看Devedge在线的老伟大的JS文件:-)

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

1

ICEfaces的内部有一个机制让会话保持活跃(该机制有时被称为“心跳”)。你可能有一个看属于documentation,并在你的web.xml中配置提及的参数(尤其是heartbeatIntervalheartbeatTimeout)。

+2

这个内部机制不保持会话的活动,其DETE当他们死亡时。间隔只是控制客户端如何交互检测死亡,但实际上并没有延长会话时间。 – jsight 2009-04-20 16:55:18

2

当我的代码已经被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> 
+1

我正面临类似的问题。你把上面的代码放在哪里?谢谢 – Tam 2009-07-10 06:01:16