You’re using the wrong @SessionScoped
annotation.
If you’ve registered the bean with the JSF @ManagedBean
annotation, then you need to import the @SessionScoped
from the JSF (javax.faces
) package as follows:
import javax.faces.bean.SessionScoped;
When you incorrectly use a CDI scope on a JSF managed bean, then there is effectively no JSF scope for the JSF managed bean and it falls back to its default @RequestScoped
, which creates a new instance in each HTTP request.
If you’ve registered the bean with the CDI @Named
annotation, then you need to import the @SessionScoped
from the CDI (javax.enterprise.context
) package as follows:
import javax.enterprise.context.SessionScoped;
When you incorrectly use a JSF scope on a CDI managed bean, then there is effectively no CDI scope for the CDI managed bean and it falls back to its default @Dependent
scope, which creates a new instance in each EL expression.