-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys!
In my ZK application I want to warn the user (displaying a message) before the session timeout.
For example, if the timeout is 5 minutes I want to warn the user at minute 4 with the following message: "Your session are about to be expired".
Is there any way to do this?
Thank you :)
add a timer and method onTimer() -> do something (display alert)
if the user is not watching the screen then the user do not will see the alert xD
Hi Zippy, thanks for your answer :)
I've only a question after reading your proposal, the Timer executes something every XX seconds/minutes... so the alert always will be shown no matter if the user is idle or active, am I right?. It could be a little annoying for a user that is working watching the screen jeje.
The issue is how to recognize that session is about to expire and then warn with a message?.
Regards.
Hi
I have created a sample, use a listener
public class MyExecListener implements ExecutionInit, UiLifeCycle { private String timerId = "timeoutNotifyTimer"; public void init(Execution exec, Execution parent) throws Exception { Timer timer = (Timer) exec.getDesktop().getAttribute(timerId); if (timer != null) { if (isSendbyMsgBox(timer, exec)) return; timer.stop(); timer.start(); } } private boolean isSendbyMsgBox(Timer timer, Execution exec) { HttpServletRequest hreq = (HttpServletRequest)exec.getNativeRequest(); for (int j = 0;; ++j) { final String uuid = hreq.getParameter("uuid_"+j); if (uuid == null) break; if (uuid.equals(timer.getUuid())) return true; } return false; } public void afterComponentAttached(Component comp, Page page) { } public void afterComponentDetached(Component comp, Page prevpage) { } public void afterComponentMoved(Component parent, Component child, Component prevparent) { } public void afterPageAttached(Page page, Desktop desktop) { Object obj = desktop.getAttribute(timerId); if (obj == null) { int tmout = desktop.getWebApp().getConfiguration() .getSessionMaxInactiveInterval(); final Timer timer = new Timer((tmout - 2) * 1000); timer.addEventListener(Events.ON_TIMER, new EventListener() { public void onEvent(Event event) throws Exception { Messagebox.show("Your session are about to be expired", "Information", Messagebox.OK, Messagebox.INFORMATION, new EventListener() { @Override public void onEvent(Event event) throws Exception { if (Messagebox.ON_OK.equals(event.getName())){ timer.start(); } } }); } }); timer.setPage(page); desktop.setAttribute(timerId, timer); timer.start(); } } public void afterPageDetached(Page page, Desktop prevdesktop) { } }
zk.xml
<listener> <listener-class>test.MyExecListener</listener-class> </listener>
but the session refreshed when the message is prompt ,
lets say my session timeout set to 30 minutes , i set it to prompt 1 minute before the session time out 29 minutes,
waited 29 minutes , message prompt with the okay button , but the session won't die after 1 minutes , it will be alive for 30 minutes because when the message is prompt , will sent a zkau request for the event onTimer, and the session just alive again.
please help .. thanks
To avoid the zkau request, you might need to do it yourself in javascript. A quick google search brought up this:
http://www.velocityreviews.com/forums/t72259-warning-that-session-about-to-timeout.html
Asked: 2011-11-22 15:38:50 +0800
Seen: 981 times
Last updated: Aug 29 '12