JSF:清除会话Scoped Bean [英] JSF: Clearing Session Scoped Bean

查看:101
本文介绍了JSF:清除会话Scoped Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,在JSF 1.2上用户关闭窗口(点击浏览器的'X')之后,如何在JSF中执行 session.remove(userBean)

I was wondering, How would I do session.remove("userBean") in JSF after user closes the window (hitting 'X' of browser) on JSF 1.2.

我想在用户点击浏览器的X后弹出确认,但不太确定如何访问或绑定<​​code>确定按钮到我定义的方法,我有清除范围bean的逻辑。或者有更好的方法吗?

I was thinking to put a confirmation pop up after user hits 'X' of browser but not quite sure how do I access or bind the Ok button to my defined method, where I have that logic to clear the scoped bean. Or is there any better approach of doing this?

任何帮助都将受到高度赞赏。

Any help would be highly appreciated.

谢谢。

推荐答案


我想知道,我该怎么做session.remove(userBean)用户在JSF 1.2上关闭窗口(点击浏览器的'X')后在JSF中。

你没有需要担心它。如果会话超时,那么肯定会删除bean。如有必要,您可以在 web.xml 中的< session-config> 中控制会话超时期限。如果你真的想挂钩会话超时/销毁,那么你可以实现 sessionDestroyed() ,或者让 UserBean 实现 HttpSessionBindingListener 并拦截 valueUnbound()

You don't need to worry about it. If the session times out, then the bean will surely be removed. You can if necessary control the session timeout period in <session-config> in web.xml. If you actually want to hook on the session timeout/destroy, then you can just implement HttpSessionListener and intercept on sessionDestroyed(), or let UserBean implement HttpSessionBindingListener and intercept on valueUnbound().

如果你真的坚持要听浏览器关闭按钮,这是一个非常多的工作后ll,那么你所能做的就是使用Javascript的 beforeunload 事件。没有别的办法。您应该记住,这是一个不标准的事件,因此并非所有Web浏览器都支持这一事件。例如。 Opera不支持此事件。简化这项工作非常方便,因为当你进行简单的香草导航或表单提交时,这个事件也会被触发,你需要在每个普通链接/按钮上禁止这个事件。您还需要触发Ajaxical请求以通知服务器关闭,因为您无法更改页面位置或提交隐藏的表单,因为浏览器将被关闭。

If you really insist in listening on the browser close button, which is quite much more work after all, then all you can do is to use the Javascript's beforeunload event. There are no other ways. You should only keep in mind that this is an unstandard event and that this is thus not per se supported by all webbrowsers. E.g. Opera doesn't support this event. It's quite a work to get this streamlined, because this event would also be fired when you do a plain vanilla navigation or a form submit, you'll need to suppress this event on every "normal" link/button. You'll also need to fire an Ajaxical request to inform the server about the close, because you cannot change the page location or submit a hidden form anymore as the browser is going to be closed.

这篇关于JSF:清除会话Scoped Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆