销毁@SessionScoped的便捷方法是什么? [英] What's the convenient way to destroy @SessionScoped?

查看:257
本文介绍了销毁@SessionScoped的便捷方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是te表中的数据未刷新.当我单击菜单中的项目时,我想破坏作用域内的会话.我知道使用Viewscoped可以实现,但我想学习其他方法. 谢谢.

My problem is te data is not refresh in the datatable. I want to destroy the session scoped when I clicked to the item in the menu.I know that it's possible with Viewscoped but I want to learn other way. Thank in advanced.

控制器:

@ManagedBean
@SessionScoped
public class MyController implements Serializable {
 //getters and setters
...........
 }

菜单:

 <td><h:outputLink styleClass="itemOutputLink" value="#  {request.contextPath}/pages/page.faces">Page1</h:outputLink></td>`

推荐答案

没有真正的干净"方法. @SessionScoped bean应该与会话一样长.因此,我再次强调,您应该更好地调整bean的作用域.

There is no really "clean" way of doing that. A @SessionScoped bean should live as long as a Session. Thus I emphasize again that you should better adjust the beans scope.

但是,如果您确实仍然需要这样做,最简单的方法就是这样做:

But if you really still need to do it, the easiest way would be to do it like this:

public static void removeSessionScopedBean(String beanName) 
{
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(beanName);
}

对于@ViewScoped豆,您可以这样操作:

For @ViewScoped beans you could do it this way:

public static void removeViewScopedBean(String beanName) 
{
    FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(beanName);
}

这篇关于销毁@SessionScoped的便捷方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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