0

I have a JSF2 application.

I have defined a Session bean using CDI.

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class UserBean implements Serializable
{
  private String userName = null;
  private String password = null;

  ... getters and setters ...
} 

Is possible to get the bean from HttpSession? For example, when I try to get it from HttpSession in a servlet class, I get null

HttpSession session = request.getSession(false);
UserBean userBean = (UserBean) session.getAttribute("userBean");

When I have worked with @ManagedBean (instead of CDI) in other applications, I could get it from HttpSession in a servlet class.

Thanks

Eduardo
  • 1,169
  • 5
  • 21
  • 56
  • As explained in the duplicate, that doesn't work, you need to use `@Inject` instead. – BalusC Aug 25 '20 at 12:57
  • Thank you very much. So CDI SessionScoped beans are not stored in HttpSession, are they? – Eduardo Aug 25 '20 at 14:26
  • Yes but not by their name as in legacy JSF @ManagedBean way. It's instead some specific `Map` managed by CDI implementation. This is unspecified so you should not try to obtain the bean that way. – BalusC Aug 25 '20 at 14:34
  • Thank you very much – Eduardo Aug 25 '20 at 15:15

0 Answers0