0

SessionCleanup on browser close, url change

asked 2008-04-09 19:17:07 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4895492

By: ansancle

I have overloaded the SessionCleanup and setup the listener in zk.xml.
If I call session.invalidate() my cleanup class get's called. The problem I am having is that it does not get called if the user goes to a different URL from my application, or if the user closes the browser.
I have checked the docs and could not find anything on this.
So what I want is for my session cleanup class to get called when the user leaves my application by going to a new URL or by closing the browser.
I swear I had a sample app that did this last year but can't find my code (of course).
All help appreciated

My Files listings :

In my web.xml :

...
<listener>
<description>Used to cleanup when a session is destroyed</description>
<display-name>ZK Session Cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
..

In my zk.xml :
<zk>
<listener>
<description>Called when the session starts</description>
<listener-class>com.dh.ui.common.zk.DHzSessionInitListener</listener-class>
</listener>
<listener>
<description>Called when the session terminates</description>
<listener-class>com.dh.ui.common.zk.DHzSessionCleanup</listener-class>
</listener>
<listener>
<description>Called when the ZK App is created</description>
<listener-class>com.dh.ui.common.zk.DHzWebAppInitListener</listener-class>
</listener>
<listener>
<description>Called when the ZK App is detroyed</description>
<listener-class>com.dh.ui.common.zk.DHzWebAppCleanup</listener-class>
</listener>
<listener>
<description>Called when the ZK Desktop is detroyed</description>
<listener-class>com.dh.ui.common.zk.DHzDesktopCleanup</listener-class>
</listener>
<listener>
<description>Called when the ZK Desktop is created</description>
<listener-class>com.dh.ui.common.zk.DHzDesktopInitListener</listener-class>
</listener>
<!-- NOTE Hacked my jboss install to create the conf directory under /opt/jboss../bin so
that ZK could find my i3-log.conf file. Need to figure how to to tell ZK where to find
it instead of me moving it. -->
<log>
<log-base>org.zkoss</log-base>
</log>
</zk>

and my class :

public class DHzSessionCleanup implements SessionCleanup {
private static Logger logger = Logger.getLogger(DHzSessionCleanup.class);

public void cleanup(Session session) throws Exception
{
logger.info("\nDHzSessionCleanup::cleanup" + session.getLocalName());
}

}



delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2008-04-10 01:03:21 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4896077

By: waterbottle

Hi,
Do you mean DesktopClean??
Session doesn't be clean after change url or close browser.

/Dennis

link publish delete flag offensive edit

answered 2008-04-11 02:12:05 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4898342

By: waterbottle

The behavior of desktop clean is correct, each desktop represent a url, please read the document here : http://www.zkoss.org/doc/devguide/ch03.html

And, because of Browser/HTML doesn't provide a method or event to let us know when user closing a browser, so we have no way to send a notify back to server.

We can only detect a unload event , which means both user change the
url(reload/redirect) or close browser, but we don't know which one is.

Does anyone have ideas?

/Dennis

link publish delete flag offensive edit

answered 2008-04-11 02:52:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4898384

By: madruga0315

Hey,

Do you have this define in zk.xml
<client-config>
...
<keep-across-visits>true</keep-across-visits>
...
</client-config>

My app have an logout button and the DesktopClean implemented.

if the keep-across-visits is set to false, the DesktopClean was called when user leaves or closes the browser, or clicked in the log out button.

but if the variable was set to true, the DesktopClean was called only when the logout button was clicked I had session.invalidate() in my button handler code, and I believe that this line called the DesktopClean.

But I noticed this a long time ago, some I cant be sure about this behavior.

Madruga

link publish delete flag offensive edit

answered 2008-04-14 14:03:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4904070

By: crisyag

Hello Madruga,

I tried to do what you suggested, but DesktopCleanup still isn't called.
Here are my settings:

- zk.xml
<listener>
<description>Desktop cleanup</description>
<listener-class>
org.sakaiproject.imsakaizk.tool.Logout
</listener-class>
</listener>

<client-config>
<keep-across-visits>false</keep-across-visits>
</client-config>

- DesktopCleanup:
package org.sakaiproject.imsakaizk.tool;

import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.util.DesktopCleanup;

public class Logout implements DesktopCleanup {

public void cleanup(Desktop arg0) throws Exception {
IMSakaiBean IMSakaiBean = (IMSakaiBean) Sessions.getCurrent().getAttribute("IMSakaiBean");
IMSakaiBean.doLogOff();
System.out.println("logout!!!");
}

}

DesktopCleanup is not called when user browses to another url or closes browser.
Any idea of what could be the problem?
Thanks a lot,

Cristiane Yaguinuma.



link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-04-09 19:17:07 +0800

Seen: 1,918 times

Last updated: Apr 14 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More