/** * * @author cirstea */ @Named(value = "ticketCreationBean") @RequestScoped public class TicketCreationBean implements Serializable { ... private static final String STATEFUL_TEST_BEAN_KEY = "STATEFUL_TEST_BEAN_KEY"; // NOT POSSIBLE: new STSB for each Managed Bean // @EJB // private TicketManager ticketManager; ... // explicit lookup private TicketManager getStatefulBean() throws ServletException { FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession httpSession = (HttpSession) facesContext.getExternalContext().getSession(false); TicketManager ticketManager = (TicketManager) httpSession.getAttribute(STATEFUL_TEST_BEAN_KEY); System.out.println("TicketManager = " + ticketManager); if (ticketManager == null) { try { InitialContext ic = new InitialContext(); ticketManager = (TicketManager) ic.lookup("java:global/GestionPersonnes/GestionPersonnes-ejb/TicketManagerBean"); httpSession.setAttribute(STATEFUL_TEST_BEAN_KEY, ticketManager); } catch (NamingException e) { throw new ServletException(e); } } return ticketManager; } private void invalidateSessionTicket() { FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession httpSession = (HttpSession) facesContext.getExternalContext().getSession(false); httpSession.setAttribute(STATEFUL_TEST_BEAN_KEY, null); } ... }