I'm new to Java and JSF. I need help with an IllegalStateException. Here's the scenario:
In my current project i have this Session Scoped bean for the application menu:
public final class MenuBean implements Serializable{
private MenuModel model;
private FacesContext context = FacesContext.getCurrentInstance();
public MenuModel getModel() {
return model;
}
public MenuBean() {
updateMenu();
}
public void updateMenu(){
Map session = (Map<String,Object>) context.getExternalContext().getSessionMap();
EUser user = (EUser) session.get(UserBean.USER_SESSION_KEY);
...
}
private MethodExpression createMethodExpression(String action) {
...
}
}
At some point of my logic, i need to update the menu, so i do this:
ExternalContext extContext = context.getExternalContext();
Map sMap = (Map<String,Object>) extContext.getSessionMap();
MenuBean menu = (MenuBean) sMap.get("menuBean");
menu.updateMenu();
The bean constructs fine, but when i try to manually update it as shown above, i get and IllegalStateException on the 1st line of the update method updateMenu()
I don't understand what's wrong, since I can get the session map with that same call whe the menu is build in the first time.
Also, using the NetBeans debugger, i can see that the instance of MenuBean is correctly recovered.
Can you guys help me?