End Conversation in Seam when the user leaves the page

我们两清 提交于 2019-12-13 14:02:14

问题


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?


回答1:


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 onbeforeunload event 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 timeout on 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:

<core:manager conversation-timeout="700000" />

Notice that conversation-timeout only affects background conversations, foreground conversation 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.



来源:https://stackoverflow.com/questions/7599288/end-conversation-in-seam-when-the-user-leaves-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!