【问题标题】:How to invoke a method on a managed bean when pressing backbutton or F5?按下后退按钮或 F5 时如何调用托管 bean 上的方法?
【发布时间】:2011-09-03 09:33:12
【问题描述】:

按下后退按钮或 F5 时如何调用托管 bean 上的方法?

【问题讨论】:

    标签: java jsf jsf-1.2


    【解决方案1】:

    如果 bean 是请求范围的,并且页面带有指示浏览器 not cache 页面的响应标头,那么您可以在 bean 的构造函数或 @PostConstruct 方法中完成这项工作。

    例如

    public class Bean {
    
        public Bean() {
            // Here, in the constructor.
        }
    
        @PostConstruct
        public void init() {
            // Or here, in the postconstructor.
        }
    
    }
    

    @PostConstruct 方法在您通过@ManagedProperty@EJB@Inject 等注入依赖项并希望基于这些依赖项进行初始化工作时特别有用。

    【讨论】:

    • 对不起,我没听懂你的回答,你能说得更具体些吗
    • 把代码放在bean的构造函数中,或者有@PostConstruct注解的方法中。此外,您需要确保浏览器不缓存 JSF 请求。你可以通过Filter 来做到这一点。
    猜你喜欢
    • 2013-09-10
    • 2012-12-26
    • 1970-01-01
    • 2014-01-19
    • 1970-01-01
    • 2016-10-27
    • 2012-02-15
    • 1970-01-01
    • 2011-01-22
    相关资源
    最近更新 更多