JSF SessionScoped bean not retaining properties

2019-08-25 04:34发布

问题:

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