Rule #1 of JSF: the more JSF-specific code you use, the more likely you're doing it wrong.
Forget the FacesContext.
Create the bean named "userId" as a Managed Bean and inject into whatever bean you had been using to do the getSessionMap().put(). Manipulate the userId bean if/when needed using POJO code.
In the servlet, do an HttpServletRequest().getSession().getAttribute('userId") to obtain the bean for servlet code to use.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Create the bean named "userId" as a Managed Bean and inject into whatever bean you had been using to do the getSessionMap().put(). Manipulate the userId bean if/when needed using POJO code.
In the servlet, do an HttpServletRequest().getSession().getAttribute('userId") to obtain the bean for servlet code to use.
You have not used
in your above examples ,
how i can set the session in any other beans and retrieve the session from a servlet or inside a servlet
I don't need to get the session map in JSF code. JSF does that automatically.
JSF session objects are HTTPSession objects. The only difference between session Managed Beans and bog-standard J2EE session beans is that JSF automatically constructs and initializes them and automatically stores them in the HTTPSession. After that, there's absolutely no way to tell the difference.
Sometimes the only way things ever got fixed is because people became uncomfortable.
I removed the ActionEvent parameter because I strongly discourage frivolous use of Listeners. Use a simple POJO action method instead.
You don't need a constructor for userBean because it's a Managed Bean and JSF will construct the UserBean instance for you and store it as a session object in accordance with the faces-config directives supplied.
You don't need FacesContext or the getSessionMap.put operation to store the UserBean as a session object because JSF did that already as part of the process of creating the managed bean, as mentioned above.
All you need to do is use the bean itself. Everything else was done for you automatically by JSF. It's what JSF is all about. Simplification.
Here's the faces-config info that goes with all of the above:
Sometimes the only way things ever got fixed is because people became uncomfortable.
eat bricks! HA! And here's another one! And a tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth