简体   繁体   English

调用应用程序作用域bean jsf

[英]Invoking application scoped bean jsf

In my applicatoin I have a application scoped bean, which I call it like this: FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("name"); 在我的应用程序中,我有一个应用程序作用域bean,我称之为: FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("name");

What is the best way to initialize it? 初始化它的最佳方法是什么?

The way I do till now it to call one of its properies in the first jsf page, for no need - just initializing the bean. 我现在的方式是在第一个jsf页面调用它的一个属性,不需要 - 只需初始化bean。

The page looks like this: 该页面如下所示:

 <h:inputHidden id="inovkeBean" value="#{myBean.nothing}"/> 

And the bean: 还有豆子:

@ApplicationScoped
public class MyBean {

String nothing;

public String getNothing() {
    return nothing;
}

} }

It works fine, just i'm asking: can anybody tell me a nicer way to initialize the bean? 它工作正常,只是我问:谁能告诉我一个更好的方法来初始化bean?

Thanks! 谢谢!

If you are using JSF2.0 mark it as eager="true" so it will get constructed when JSF context will get initilized 如果您正在使用JSF2.0将其标记为eager="true"那么当JSF上下文将被初始化时它将被构造

@ManagedBean(eager=true)
@ApplicationScoped
public class SomePojo { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM