Hi all,

I'm trying to implement a timeout mechanism that redirects to some page
after a given period of inactivity. I know that this is a common problem and
the mechanism (using AbstractAjaxTimerBehavior to decrement a timer in the
session) in this blog post sort of works:

http://javathoughts.capesugarbird.com/2007/08/user-configurable-timeout-for-your.html

But, as the author says, it doesn't work for Ajax requests. He suggests that
all Ajax requests call some timer reset method somewhere. Our app is heavily
Ajaxy, and I really don't want to copy paste even one line call into every
different ajax behavior, link, button etc. It's also important that the
timer be reset for every Ajax call as we have some large pages that the user
may spend some time filling out, but would be relatively talkative with Ajax
requests. Using a common superclass is impossible as there are too many
different classes and interfaces that Ajax requests can be generated from.

I came up with this idea of using the onRequestTargetSet in a custom
RequestCycle. It seems that this gets called for Ajax and non Ajax requests.
The problem is that it also gets called for the Timer requests. I worked
around this by checking if the target is a BehaviorRequestTarget and if the
selected behavior is an instance of AbstractAjaxTimerBehavior. To do this, I
had to copy a bit of code out of BehaviorRequestTarget (the bit that looks
up the requested behavior). Also, I ignored AjaxRequestTargets as it seems
that after invoking an ajax listener target, one of these is set as the
request target, but this is not a user initiated request target (for
example, a single timer tick generates two onRequestTargetSets, one with the
TimerBehavior, the other with just an AjaxRequestTarget).

This solution seems to be working so far. I was wondering if anybody else
has found a better way to do this or could tell me if there's some problem
I'm overlooking with my solution?

Thanks,
Neil

Reply via email to