0

Do something before user close the page

asked 2009-08-26 13:20:55 +0800

evpole gravatar image evpole
481 2

usually we have to do something before user exit, for example, close the connection for databse, or destroy the session.

one way is to use DesktopCleanup listener,but i've failed.



define listener in zk.xml:
<listener>
<description>Called when the ZK Desktop is detroyed</description>
<listener-class>mypackage.MyDesktopCleanup</listener-class>
</listener>
define method in MyDesktopCleanup:
public void cleanup(Desktop desktop) throws Exception {}


sencond way is to listen it in client via javascript,and send it back to the server:

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<script>
function window.onbeforeunload()
{window.event.returnValue="are you sure to quit ?";
comm.onEvent(this,"onExit");
}
</script>
<window id="mainwindow" apply="mypackage.MainController" />


but i don't know where to receive this event.
dose "this" mean the page ?
why couldn't i use "#{mainwindow}" instead of "this", then i could receive this event in MainController.

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-08-26 19:40:45 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-08-27 23:03:07 +0800

Hmmmm, we have this theme in various threads. I mean that's a problem of the http protocol.
Who can send something to the server if the user turns off the power of his PC or close
the browser or change the URL?

So you see it right. In my eyes too a probable way is to do the cleanings on the server:

1. decrease the SessionTimeout
2. take a Conection Manager. Hibernate have its own session and handles them.
3. Let tomcat hold the connection to the database

regards
Stephan

link publish delete flag offensive edit

answered 2009-08-27 12:42:53 +0800

evpole gravatar image evpole
481 2

Thank you very much !

It's good idea to Use database connection pool to manage connections.

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: 2009-08-26 13:20:55 +0800

Seen: 284 times

Last updated: Aug 27 '09

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