会话结束时销毁视图范围的bean [英] Destroying view-scoped beans when session ends

查看:125
本文介绍了会话结束时销毁视图范围的bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与此相关(可能还有其他问题):

@ PreDestroy永远不会调用@ViewScoped



如前所述,有没有简单的解决方案可以使视图范围的bean在导航过程中销毁,同样的情况在会话过期时也是如此。

发布一个非平凡的方法(调用 @ PreDestroy 方法)JSF视图范围的bean看起来像,或者更具体地说,只要会话过期了?



我正在使用Java EE 6和GlassFish 3.1.2上的Mojarra 2.1.x。

解决方案

创建 @SessionScoped bean来保存资源(在某些集合/数组中?)并将它注入到 @ViewScoped bean中,然后依靠 @PreDestroy



确实,这样资源就会亮起来比你想要的要长,但这是你可以得到的最简单可靠的解决方案。如果你想在视图范围的bean中保留 @PreDestroy ,那么你需要以某种方式确保最终用户始终通过HTTP POST请求执行导航查看范围的bean。您无法可靠地保证(最终用户的PC可能会崩溃等)。


My question is related to this one (and probably others):

@PreDestroy never called on @ViewScoped

As stated there, there's no trivial solution to either have view-scoped beans destroyed upon navigation and the same seems to hold true for when the session expires.

What would a non-trivial approach to release (calling the @PreDestroy method) JSF view-scoped beans look like, or more specifically as soon as the session expires?

I'm using Java EE 6 and Mojarra 2.1.x on GlassFish 3.1.2.

解决方案

Create a @SessionScoped bean to hold the resources (in some collection/array?) and inject it in the @ViewScoped bean and then rely on the @PreDestroy of the session scoped bean.

True, this way the resources live a little longer than you want, but that's the most easy and reliable solution you can get. If you want to keep the @PreDestroy in the view scoped bean, then you'd need to somehow make sure that the enduser always performs navigation by a HTTP POST request on exactly this view scoped bean. You can't reliably guarantee that (the enduser's PC might crash and so on).

这篇关于会话结束时销毁视图范围的bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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