【问题标题】:JSF init not called on page refresh页面刷新时未调用 JSF init
【发布时间】:2018-05-13 20:34:30
【问题描述】:

我有 jsf 会话范围的 bean。它的 init 方法带有注释 @PostConstruct 在第一次加载页面时调用,但不是在每次重新加载或刷新时调用。我想在每次页面刷新时调用一些方法。我需要在 xhtml 文件中使用什么注释或更改

【问题讨论】:

  • 您使用的是哪个注释?如果您使用 @ViewScope 注释,它将在每次加载页面时加载。如果您使用@SessionScoped,则数据将通过所有用户会话持久化。
  • 我正在使用会话范围,我希望每次刷新都调用方法
  • 改成ViewScope就好了。

标签: jsf


【解决方案1】:

尝试如下更改您的注释标签

只需将其更改为 ViewScope。导入 javax.annotation.PostConstruct;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class YourControllerClass implements Serializable {

    @PostConstruct
    public void init(){

    }
}

【讨论】:

    【解决方案2】:

    如果你想在每次页面刷新时调用一个方法,最好使用ComponentSystemEvent

    您可以参考以下链接 https://www.tutorialspoint.com/jsf/jsf_applicationevents_tag.htm

    【讨论】:

      猜你喜欢
      • 2012-08-13
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多