Bruce. Let me see if I can find some time during weekend to play a bit with the links your provided and come up with a more robust solution.
On Fri, May 16, 2014 at 3:57 PM, Bruce Lombardi <brlom...@gmail.com> wrote: > First, thank you for your continuing interest. This is the best support > group experience I've ever had. I hope the message come in the right > sequence. Lke Ernesto and other A saw the sequencing problem cause by the > apache server problem. > > I ran the test that Martin suggestion with 6.16.0-SNAPSHOTand got the > same behavior, which is what Ernesto and I suspected would happen. > > I'm sorry, but I don't know a lot about JavaScript so I'm having with > certain things. I read this article in stackoverflow: > > > https://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs > > Which lead to this: > > > http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome > > > Which contained an example of a script that doesn’t work correctly (if you > go to it, you will see that it walks the word "test" across the screen. > If you go to another tab and come back "test" hasn’t moved) > > http://jsfiddle.net/7f6DX/3/ > > > and this example that works (does the same thing but you can see that > "test" moves even when you go to another tab - but don't go away too long > it will reach the end and disappear). > > http://jsfiddle.net/7f6DX/31/ > > Do you think the last (working) script could be adapted for our timeout? > > Regards, > Bruce > > > > -----Original Message----- > From: Ernesto Reinaldo Barreiro [mailto:reier...@gmail.com] > Sent: Tuesday, May 13, 2014 1:59 AM > To: users@wicket.apache.org > Subject: Re: Ajax timer not counting when tab doesn't have focus? > > Martin, > > Thanks for pointing out this. The exact JavaScript enabling this feature > can be found here > > > https://github.com/reiern70/antilia-bits/blob/master/client-sign-out-parent/client-sign-out/src/main/java/com/antilia/signout/InactivitySignOutPanel.js > > Maybe there is a memory leak in here as well... but I do not see the > relation with WICKET-5570 as I do not use any of the AJAX timer behavior, > see > > > https://github.com/reiern70/antilia-bits/blob/master/client-sign-out-parent/client-sign-out/src/main/java/com/antilia/signout/InactivitySignOutPanel.java > > As Bruce describes the problem it sounds like if by switching to other tab > browser give less "priority" to the execution of JavaScript in inactive > tabs. > > > > On Mon, May 12, 2014 at 9:28 PM, Martin Grigorov <mgrigo...@apache.org > >wrote: > > > It could be that https://issues.apache.org/jira/browse/WICKET-5570 is > > the issue. > > Please try with 6.16.0-SNAPSHOT if you can. > > > > Martin Grigorov > > Wicket Training and Consulting > > > > > > On Mon, May 12, 2014 at 8:02 PM, Bruce Lombardi <brlom...@gmail.com> > > wrote: > > > > > Thanks Ernesto. > > > > > > Yes, I do mean another browser tab. I have some new information. The > > timer > > > seems to slow way down, but not stop counting down when the user > > > switches focus to another tab, either opening a new tab, or just > > > clicking on > > another > > > tab. This is happening in both Chrome and Firefox. > > > > > > I thought that my code was never timing out, but further > > > experimentation with a shorter timeout period shows that it is doing > > > the same thing as > > the > > > demo. That is, timing out in about 10 second when you stay on the > > > tab, > > but > > > taking 3 minutes or longer to timeout when if you change focus to a > > > different tab. > > > > > > I would appreciate it if you could look at your demo and see the > > > behavior and then see if you have any ideas. > > > > > > As for my code, I really feel they difference with your code are > > > insignificant especially now that I know the behavior is the same. > > > > > > See below for the differences. > > > > > > Thanks again, > > > > > > Bruce > > > > > > > > > Code. > > > > > > I have your InactivitySignOutPanel.java, InactivitySignOutPanel.html > > > and InactivitySignOutPanel.js from the GitHub site with one slight > > modification > > > in InactivitySignOutPanel.java (see below). > > > > > > I setup my panel in a base class that serves as a superclass for > > > all > > the > > > Web pages in the application (extends WebPage) I have a method that > > > is called to setup the timeout. Here is the method. > > > > > > public void setupTimeout() { > > > > > > // Change the following value to change the session > > > timeout. > > > int numberOfMinutesUntilTimeout = 15; > > > > > > int secondsPerMinute = 60; > > > int secondsToTimeout =numberOfMinutesUntilTimeout * > > > secondsPerMinute; > > > > > > add(new InactivitySignOutPanel("timeout", > > > Duration.seconds(secondsToTimeout)) { > > > > > > private static final long serialVersionUID = 1L; > > > > > > protected String getOnTimeChangedFunction() { > > > return > > > "function(timeRemaining){if(!window.countDown) { window.countDown = > > > $('#countDown'); } $(window.countDown).html(timeRemaining);}"; > > > } > > > }); > > > > > > add( new AjaxLink<Void>("link") { > > > > > > private static final long serialVersionUID = > > > 1L; > > > > > > @Override > > > public void onClick(AjaxRequestTarget target) { > > > // do nothing > > > } > > > }); > > > } > > > > > > Here is the core code in InactivitySignOutPanel I have just modified > > > the respond method to call > > > > > > > > > ((WebDocsSession)WebSession.get()).processLogoutorSessionExpiration( > > > ); > > > > > > > > setResponsePage(WebApplication.get().getApplicationSettings().getPageE > > xpiredErrorPage()); > > > > > > so that the application does the right thing. Note: a break point > > > shows that this method is never call when the user is on another tab. > > > > > > > > > public InactivitySignOutPanel(String id, Duration duration) { > > > this(id, Model.of(duration)); > > > } > > > > > > public InactivitySignOutPanel(String id, IModel<Duration> model) { > > > super(id, model); > > > setRenderBodyOnly(true); > > > add(ajaxBehavior = new AbstractDefaultAjaxBehavior() { > > > > > > private static final long serialVersionUID = > > > 1L; > > > > > > @Override > > > protected void respond(AjaxRequestTarget target) { > > > beforeSignOut(target); > > > > > > ((WebDocsSession)WebSession.get()).processLogoutOrSessionExpiration( > > > ); > > > > > > > > setResponsePage(WebApplication.get().getApplicationSettings().getPageE > > xpiredErrorPage()); > > > } > > > > > > @Override > > > protected void onBind() { > > > // panel will not be repainted, no need to markup > > > markup id. > > > } > > > > > > @Override > > > public void renderHead(Component component, > > > IHeaderResponse > > > response) { > > > super.renderHead(component, response); > > > response.render(JavaScriptHeaderItem.forReference(JS)); > > > } > > > }); > > > } > > > > > > -----Original Message----- > > > From: Ernesto Reinaldo Barreiro [mailto:reier...@gmail.com] > > > Sent: Monday, May 12, 2014 11:39 AM > > > To: users@wicket.apache.org > > > Subject: Re: Ajax timer not counting when tab doesn't have focus? > > > > > > Hi Bruce, > > > > > > > > > On Mon, May 12, 2014 at 4:52 PM, Bruce Lombardi <brlom...@gmail.com> > > > wrote: > > > > > > > This message is related to an original thread "Link to Wicket > > > > page from Javascript" but the focus is changed so much that I > > > > though a new title would be better. In the earlier thread I asked > > > > about linking to a Wicket page, but the real need was for help in > > > > implementing a session timeout that would send the user to a > > > > timeout page after a period of inactivity and would reset whenever > > > > a user clicked any button on the page. > > > > > > > > > > > > > > > > Ernesto Reinaldo Barreiro sent me links(see below) to a working > > > > demo that did exactly what I required. I used that code and > > > > everything seemed to work perfectly. However, I have since > > > > discovered that my timer does not seem to function correctly if > > > > the user goes to another tab. It seems like the timer stops timing > > > > down or slows way down until the user comes back to the original tab. > > > > > > > > Do you mean another browser tab? > > > > > > > > > > > > > > > I checked Ernesto's demo. If I go to the demo page and stay there > > > > it times out after roughly the defined 10 second timeout period, > > > > but if I go to the demo page, then click on another tab, it > > > > eventually times out, but after more than 3 minutes. My code, > > > > however, never seems to seem to timeout the page if I go to another > tab. > > > > > > > > Does this happens in a all browsers? Or in particular one? > > > > > > Mind that this is just a quick "something" I build to illustrate the > > > idea... So, it might not be bullet proof. > > > > > > > > > > > > > > I really need this to work to fulfill a requirement and it is > > > > preventing the launch of our software. It all works fine except > > > > if the user goes to a different tab. > > > > > > > > > > > > > > > > Ernesto, or anyone, do you know why this is happening. Is the ajax > > > > timer stopping when the tab is not selected? Why is the demo > > > > eventually timing out while application is not (can't see any real > > > > difference in the code)? > > > > > > > > > > Without seeing your code or a quick-start app illustrating the > > > problem > > it > > > might be difficult to point out what's going on. > > > > > > > > > > > Is there any way to get a better handle on this (e.g., firebug)? > > > > If the ajax timer is stopping, could something be done, perhaps > > > > using absolute elapsed time, to expire the session immediately if > > > > the user goes back to the tab? > > > > The latter is not ideal but might be acceptable. > > > > > > > > > > > > > > > > (Note: My session timeout in web.xml is 30 minutes, client timeout > > > > is > > > > 15 minutes, but for testing I set it to 10 seconds). > > > > > > > > > > > > > > > > > > > > > > > > // Links > > > > > > > > > > > > > > > > Demo of Example > > > > > > > > > > > > > > > > http://107.170.4.97:9080/client-sign-out-demo/?0 > > > > > > > > > > > > > > > > > > > > > > > > Code that sets up example > > > > > > > > > > > > > > > > https://github.com/reiern70/antilia-bits/blob/master/client-sign-o > > > > ut-p > > > > aren > > > > > > > > t/client-sign-out-demo/src/main/java/com/antilia/HomePage.java > > > > > > > > > > > > > > > > > > > > > > > > Code that provides the implementation (We have this code in > > > > package > > > > > > > > com.xyzco.web.docs.presentation.helpers.timeout) > > > > > > > > > > > > > > > > > > > > > > > > https://github.com/reiern70/antilia-bits/tree/master/client-sign-o > > > > ut-p > > > > aren > > > > > > > > t/client-sign-out-demo/src/main/java/com/antilia > > > > > > > > > > > > > > > > Thanks, > > > > > > > > Bruce > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > > > > From: Bruce Lombardi [mailto:brlom...@gmail.com] > > > > > > > > Sent: Monday, March 17, 2014 8:24 AM > > > > > > > > To: users@wicket.apache.org > > > > > > > > Subject: Re: Link to Wicket page from Javascript > > > > > > > > > > > > > > > > Thanks, this is very helpful. > > > > > > > > > > > > > > > > Bruce > > > > > > > > > > > > > > > > Sent from my iPad > > > > > > > > > > > > > > > > > On Mar 17, 2014, at 4:52 AM, Ernesto Reinaldo Barreiro > > > > > > > > <reier...@gmail.com> wrote: > > > > > > > > > > > > > > > > > > You can see it at work here > > > > > > > > > > > > > > > > > > http://107.170.4.97:9080/client-sign-out-demo/ > > > > > > > > > > > > > > > > > > > > > > > > > > > On Mon, Mar 17, 2014 at 9:18 AM, Ernesto Reinaldo Barreiro < > > > > > > > > > reier...@gmail.com> wrote: > > > > > > > > > > > > > > > > > >> Martin, > > > > > > > > >> > > > > > > > > >> What I mean is something that triggers the sign out before > > > > >> serve side > > > > > > > > >> session expires... and trigger this expire event. > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> https://github.com/reiern70/antilia-bits/blob/master/client-sig > > > > >> n-ou > > > > >> t- > > > > > > > > >> parent/client-sign-out/src/main/java/com/antilia/signout/Inacti > > > > >> vity > > > > >> Si > > > > > > > > >> gnOutPanel.java > > > > > > > > >> > > > > > > > > >> https://github.com/reiern70/antilia-bits/blob/master/client-sig > > > > >> n-ou > > > > >> t- > > > > > > > > >> parent/client-sign-out/src/main/java/com/antilia/signout/Inacti > > > > >> vity > > > > >> Si > > > > > > > > >> gnOutPanel.js > > > > > > > > >> > > > > > > > > >> The above seem to work. You use it as in > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> https://github.com/reiern70/antilia-bits/blob/master/client-sig > > > > >> n-ou > > > > >> t- > > > > > > > > >> parent/client-sign-out-demo/src/main/java/com/antilia/HomePage. > > > > >> java > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> On Mon, Mar 17, 2014 at 9:11 AM, Martin Grigorov > > > > > > > > < <mailto:mgrigo...@apache.org> mgrigo...@apache.org>wrote: > > > > > > > > >> > > > > > > > > >>> Hi, > > > > > > > > >>> > > > > > > > > >>> On Fri, Mar 14, 2014 at 9:25 PM, Ernesto Reinaldo Barreiro < > > > > > > > > >>> reier...@gmail.com> wrote: > > > > > > > > >>> > > > > > > > > >>>> Hi, > > > > > > > > >>>> > > > > > > > > >>>> I would implement this as.. > > > > > > > > >>>> > > > > > > > > >>>> 1- A JS function that counts how much time has passed since > > > > >>>> last > > > > > > > > >>>> AJAX request. Once a certain threshold is passed an AJAX > > > > >>>> request is > > > > > > > > >>>> sent to > > > > > > > > >>> the > > > > > > > > >>>> page. > > > > > > > > >>>> 2- An AbstractAjaxBehavior that is added to the page. I would > > > > >>>> use > > > > > > > > >>>> it as context for AJAX request on 1). > > > > > > > > >>> > > > > > > > > >>> at that time the session should be already expired. > > > > > > > > >>> > > > > > > > > >>> But this can be used to do what is needed here - Wicket will > > > > > > > > >>> redirect to the configured PageExpiredErrorPage. > > > > > > > > >>> > > > > > > > > >>> > > > > > > > > >>>> 3- On the respond of AJAXBehavior you redirect to > > > > > > > > >>>> SessionTimeoutPage > > > > > > > > >>> and > > > > > > > > >>>> invalidate the session. > > > > > > > > >>>> > > > > > > > > >>>> > > > > > > > > >>>> > > > > > > > > >>>> On Fri, Mar 14, 2014 at 8:07 PM, Bruce Lombardi > > > > > > > > >>>> <brlom...@gmail.com> > > > > > > > > >>>> wrote: > > > > > > > > >>>> > > > > > > > > >>>>> Hi, > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> An earlier question I asked about session timeouts was > > > > >>>>> answered by > > > > > > > > >>> Martin > > > > > > > > >>>>> Grigorov. I am implementing his suggestion and have a JQuery > > > > > > > > >>>>> script > > > > > > > > >>> what > > > > > > > > >>>>> sets a timer that times out after a certain period of > inactivity. > > > > > > > > >>>>> The timeout triggers a function call. Currently, for a > > > > >>>>> quick > > > > > > > > >>>>> test, I > > > > > > > > >>> have > > > > > > > > >>>>> that function use location.href to go to an arbitrary static > > > > >>>>> web > > > > > > > > >>>>> page > > > > > > > > >>>> like > > > > > > > > >>>>> this: > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> function whenUserIdle(){ > > > > > > > > >>>>> > > > > > > > > >>>>> location.href = > > > > > > > > >>>>> 'http://www.natural-environment.com'; > > > > > > > > >>>>> > > > > > > > > >>>>> } > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> That works fine, but now I need to make it go to a Wicket > > > > >>>>> page in > > > > > > > > >>>>> my application, similar to what would happen if I had an > > > > >>>>> anchor > > > > > > > > >>>>> tag > > > > > > > > like: > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> <a wicket:id=" SessionTimeoutPage" > > > > >>>>> href="#">SessionTimeoutPage</a> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> But I can't figure out how to do this in the javascript > function. > > > > > > > > >>>>> Can anyone tell me how to call the Wicket page from the > > > > >>>>> javascript > > > > > > > > >>>>> function? > > > > > > > > >>> > > > > > > > > >>> You can use <script wicket:id="expirationUrl"></script> and a > > > > > > > > >>> Label("expirationUrl", "window.expirePageUrl ='" + > > > > > > > > >>> urlFor(SessionTimeoutPage.class) + "';"); Then use it with: > > > > > > > > >>> location.href = window.expirePageUrl'; > > > > > > > > >>> > > > > > > > > >>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> Thanks, > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> > > > > > > > > >>>>> Bruce > > > > > > > > >>>> > > > > > > > > >>>> > > > > > > > > >>>> -- > > > > > > > > >>>> Regards - Ernesto Reinaldo Barreiro > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> -- > > > > > > > > >> Regards - Ernesto Reinaldo Barreiro > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > Regards - Ernesto Reinaldo Barreiro > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > Regards - Ernesto Reinaldo Barreiro > > > > > > > > > -------------------------------------------------------------------- > > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > > > > > > -- > Regards - Ernesto Reinaldo Barreiro > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Regards - Ernesto Reinaldo Barreiro