Is there some way to end a conversation in Seam 2 when the user leaves the page? I know, that I can of course end a conversation in the navigation rules( see this post), but I want to end a conversation when the user enters an url in the address bar of the browser.
Could this be achieved via Javascript (for example with onbeforeunload)? But how to stop a conversation via javascript?
You could use JavaScript to implement an
onbeforeunloadevent and use AJAX to communicate the user leaving to the site and end all your conversations. However, I don't recommend you this solution because you cannot rely on a event happening on the browser, Javascript is not a good option, since you can disable it client-side (Not only that, but the browser may crash, the network connection may drop, etc..)I think an alternative aproach to do this is by setting a seam
conversation timeouton the server. You can try and reduce the timeout in order to close inactive conversation faster, when the user leave your page.Configuring the conversation-timeout period can be accomplished through the following in your
components.xml:Notice that conversation-timeout only affects
backgroundconversations,foregroundconversation will only timeout when the session times out which is relevant for your requirements.More information about conversation time out can be found in this article.