PDA

View Full Version : Is there this kind of listener?



pirusira
4 Jul 2010, 10:53 PM
Hello, all.

I've been adding a function to all components and elements to check session status.
Meanwhile, I've got a question : Is there a listener for all components' and elements' events?
Because I had to find all the components and elements' event to add the session check function.
It's too annoying work.

Any ideas?

Thanks in advance.
Stan

Animal
4 Jul 2010, 11:09 PM
Pass the session timeout value into your page..



<script type="text/javascript">
MyApp.timeoutValueSeconds = <%=session.getMaxInactiveInterval()%>;
...
</script>


Then you can start a timeout at app startup for that time.

And from then on use class level observability on the Ext.data.Connection class to refire the timeout on each Ajax request.

That way, you can time the client out in synch with the server.

Condor
4 Jul 2010, 11:15 PM
You could monitor mousedown/mousemove/keypress events on the body. Only stopped events would not bubble up to the body.

EventManager can't be monitored, because the essential methods are private, but you could also monitor Observable.fireEvent to catch any Observable event.

So you would end up with:

var endSession = function(){
// Do stuff
},
endSessionTask = new Ext.util.DelayedTask(endSession),
delayEndSession = function(){
endSessionTask.delay(60000);
};
Ext.getBody().on({
mousedown: delayEndSession,
mousemove: delayEndSession,
keypress: delayEndSession
});
Ext.util.Observable.prototype.fireEvent = Ext.util.Observable.prototype.fireEvent.fireEvent.createInterceptor(delayEndSession);

Animal
4 Jul 2010, 11:52 PM
Mouse and key events should not interrupt and re-schedule a session timeout.

The server will timeout regardless of any keyboard or mouse interactions you might be doing, and your next Ajax transaction will fail.

The client and the server should timeout in sycnhrony.