开发者

session expiration real time remaining time

In a JSF 2.0 context, session.getMaxInactiveInterval() returns the session expiration remnant time, a static way. Is there any workaround allowing one to display the remaining time in realtime? Something like a system thread.

In my Web app, I am using a primeFaces component (a modal dialog) that shows itself after a cert开发者_StackOverflow中文版ain time of user inactivity (tmeout) displaying a message "Are you there?". Actually, what I want is to add something like the following to that dialog:

<h:outputText id="remainder" value="#{sessionEar.maxInactiveInterval}" >
<f:ajax execute="@form" render="remainder"  event="????"/>
</h:outputText>

So the idea is to re-render the <h:outputText /> each 5 seconds or each 60 seconds (1 minute : supposing showing the seconds in real time is not that easy)! So that it updates the remnant time before session expires.

How can I do this? Otherwise, do you have any better solution?


I would suggest using a javascript based timer that starts by reading the value of #remainder. Also this way you wont have to do any round-trips for requesting the new time.

var interval=setInterval('updateSessionTimer()',1000);  // every second
var remainder = document.getElemetById('remainder');
function updateSessionTimer()
{
    secondsLeft = parseInt( remainder.innerText );
    remainder.innerHTML = secondsLeft-1;
}


I finished using PrimeFaces Poll component which is straight fit.

<p:poll interval="1"  update="remainder" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜