I know I can put/get session scope variables like this.
FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put(SESSION_KEY_SOME, some);
Then can't I access the value like this?
@ManagedBean
@SessionScoped
public class SomeOtherBean {
@ManagedProperty("#{sessionScope.some}")
private Some some;
}
The value is null.
@ManagedPropertyruns during creation/instantiation of the@ManagedBean.So, when the
@ManagedBeanis created before the#{sessionScope.some}is set for first time, then it will still remainnullin the@ManagedBean. It will only work when@ManagedBeanis created after the#{sessionScope.some}is set for the first time.There are basically three ways to achieve the desired behavior.
Replace
private Some somebyexternalContext.getSessionMap().get("some").Replace
@SessionScopedby@RequestScoped.Replace
externalContext.getSessionMap().put("some", some)by directly setting it as bean property.See also: