ApplicationScoped Bean eager = true在切换到不同视图时会破坏

时间:2015-05-19 00:30:19

标签: jsf primefaces

JSF2,Primefaces 3.3.FINAL,Spring

我有ApplicationScoped Bean用于在启动服务器期间加载所有下拉数据。我通过ManagedProperty注释引用了相同的bean。但是当切换视图时,bean会被破坏,我需要再次重新创建bean和数据。

示例代码:

   @ManagedBean(name = "refDataBean", eager = true)
   @ApplicationScoped
   public class RefDataBean extends AbsBackingBean implements Serializable{
   ....
     @PostConstruct
     public void init(){
     //load multiple drop down data - populateData-db call
     }
   }


   @ManagedBean(name = "searchViewBean")
   @ViewScoped
   public class SearchViewBean{

   @ManagedProperty(value = "#{refDataBean}")
   private RefDataBean        refDataBean;
    @PostConstruct
    public void init() { //getUser object }

   public User retrieveUser(User user) {
           List<User> userList = refDataBean.getUserList();
   }

   public PICTSRefDataBean getPictsRefDataBean() {
      return pictsRefDataBean;
   }

   public void setPictsRefDataBean(final PICTSRefDataBean pictsRefDataBean)      
   {     this.pictsRefDataBean = pictsRefDataBean;  }

   } 

在一个页面/视图中,user.xhtml

<h:selectOneMenu  value="#{searchViewBean.selectedUser}" >
    <f:selectItems value="#{refDataBean.userList}" var="taskUser"
            itemLabel="#{taskUser.fullNameAndId}"
            itemValue="#{taskUser.networkLogin}"></f:selectItems>              
</h:selectOneMenu>

当切换到另一个页面team.xhtml时,refDataBean为null,它转到RefDataBean的PostConstruct方法,再次构建整个下拉列表。由于它是静态数据,我希望加载一次,并且应该能够在任何页面中访问。我知道切换到不同视图时,View范围中的对象会被销毁。如何限制?或者我错过了什么?请帮忙

0 个答案:

没有答案