I ended up finding a workaround that allows me to get a @Statefulbean link :
I created a @Named @Singleton @Startupbean SessionController tag that contains a local one HashMap<String, UserSession> sessionMapwith links to my @Statefulbeans:
@Named
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class SessionController {
private HashMap<String, UserSession> sessionMap;
@PostConstruct
void init() {
sessionMap = new HashMap<String, UserSession>();
}
@PreDestroy
void terminate() {
for (UserSession us : sessionMap.values()) {
us.logoutCleanUp();
}
sessionMap.clear();
}
public void addSession(String sessionId, UserSession us) {
sessionMap.put(sessionId, us);
System.out.println("New Session added: " + sessionId);
}
public UserSession getCurrentUserSession() {
FacesContext context = FacesContext.getCurrentInstance();
String sessionId = ((HttpSession) context.getExternalContext().getSession(false)).getId();
return sessionMap.get(sessionId);
}
}
bean @PostConstruct:
public class UserSession implements Serializable {
@Inject SessionController sc;
...
@PostConstruct
void init() {
FacesContext context = FacesContext.getCurrentInstance();
String sessionId = ((HttpSession) context.getExternalContext().getSession(true)).getId();
sc.addSession(sessionId, this);
}
.getSession(true), , . , this , @PostConstruct ...
EntityListener ( ) :
SessionController sc = (SessionController) new InitialContext().lookup("java:module/SessionController");
UserSession us = sc.getCurrentUserSession();
CDI beans
@Inject SessionController sc;
, , , - ( FacesContext context = FacesContext.getCurrentInstance() ). beans (, , EntityListeners) @javax.jws.WebService @Stateless beans. ( : ) ( ), sessionId ( ). , , SessionContext bean sessionId - . , - ...