如何触发对viewscoped bean的破坏? [英] How to trigger destruction of viewscoped bean?

查看:98
本文介绍了如何触发对viewscoped bean的破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个@ViewScoped注释的托管bean,其@PostContruct方法从数据库中获取一个列表,以显示在视图的表中. 现在,当我删除一个项目时,我希望在视图中看到更改.
为了保持这种动态和可重用性,我只想从数据库中删除(而不是从列表中手动删除).因此,我需要销毁/重新创建我认为的bean.现在,我通过导航到同一视图来执行此操作.但是我的方法不可重用.
我可以手动销毁bean或导航到同一视图,而无需显式导航到该特定视图(可重用性)吗?

I have a @ViewScoped-annotated managedbean whose @PostContruct-method fetches a list from database to be displayed in a table in the view.
Now when I delete an item I want the changes to be seen in the view.
To keep this dynamic and reusable I only want to delete from database (not manually from list). So I need to destroy/recreate the bean I suppose. Now I do this by navigating to the same view. But the way I do is not reusable.
Can I just destroy the bean manually or navigate to the same view without explicitly navigating to THAT specific view (reusability)?

我正在使用JSF 2.1

I am using JSF 2.1

推荐答案

您已经在正确的轨道上. viewMap就像其他任何地图一样;您可以按名称删除ViewScoped bean.请原谅残暴的链接:

You're already on the right track. viewMap is just like any other map; You can remove a ViewScoped bean by name. Please excuse the atrocious chaining:

FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("yourBean");

这篇关于如何触发对viewscoped bean的破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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