FacesContext is stored in the HTTP request stream. You should absolutely not declare and assign it as an instance variable of an instance that lives longer than an HTTP request (and preferably also just not when it already requests based on - a bad design). The FacesContext instance FacesContext freed and FacesContext when the HTTP request completes. In any subsequent HTTP request, the instance is no longer valid. There are funds from an illegal state. This explains the IllegalStateException you see.
You need to delete the following line:
private FacesContext context = FacesContext.getCurrentInstance();
And correct your code so that it is only threadlocal in the method block:
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
You can always assign it as a variable, but you only need to save this threadlocal:
FacesContext context = FacesContext.getCurrentInstance(); Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
Unrelated to the specific issue, using @ManagedProperty was easier in this particular case.
public final class MenuBean implements Serializable { @ManagedProperty("#{user}") private EUser user;
JSF will then introduce it for you.
Balusc
source share