I have a ManagedBean
(SecurityTokenController
) that use a Stateful SessionBean
(SecurityTokenClient
).
Each time I call the controller, a new SecurityTokenClient
bean is instantiated, so I lose the state. What am I doing wrong?
Here is the code of the ManagedBean
:
@ManagedBean
public class SecurityTokenController implements Serializable {
@EJB
SecurityTokenClient client;
public String askToken(){
return client.getToken().toString();
}
}
Here there is the code of the Stateful SessionBean
:
@Stateful
@SessionScoped
public class SecurityTokenClient implements Serializable {
SecurityToken securityToken;
public SecurityTokenVO getToken(){
if ( null == this.securityToken ) {
this.securityToken = new SecurityToken();
}
return this.securityToken;
}
}
So, every time I call this bean the securityToken
is null
. The injected EJB
is always a different one.
What did I do wrong?