JSF SessionScoped bean not retaining properties

和自甴很熟 提交于 2019-12-11 16:26:04

问题


I am working on a jsf app using primefaces and have a SalesBean which is used by various views

@ManagedBean
@ViewScoped
public class SalesBean implements Serializable, IGlobals {

private static final long serialVersionUID = 2384518099615211725L;

@ManagedProperty(value = "#{applicationBean}")
private ApplicationBean application;

@ManagedProperty(value = "#{sessionSettingsBean}")
private SessionSettingsBean settings;

    @PostConstruct
public void refresh() {     
    this.trader=settings.getSelectedTrader();
}



import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped

public class SessionSettingsBean implements Serializable {

private Trader selectedTrader;

        public Trader getSelectedTrader() {
    return selectedTrader;
}

public void setSelectedTrader(Trader selectedTrader) {
    this.selectedTrader = selectedTrader;
}
}

The postConstruct should mean that the SalesBean properties have references to those of the sessionBean.

In one view, I save away properties to the injected session bean

settings.setSelectedTrader(trader);

In another view, I want to use settings.getSelectedTrader(), but when I debug the @PostConstruct, the selectedTrader property of settings is null, even though I checked that it was instantiated correctly when originally set in the sessionBean by a previous view.

Can anybody give a pointer as to what is going on, there cant be several versions of the session bean presumably(only one constructor is called at the start of the session), so how can properties be nulled between views - any ideas / suggestions greatly appreciated

来源:https://stackoverflow.com/questions/16967524/jsf-sessionscoped-bean-not-retaining-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!