I have a Session scoped bean
@SessionScoped
public class UserData implements Serializable {
private String uid;
public String getUid() {
return uid;
}
public void setUid(final String uid) {
this.uid = uid;
}
I'm setting a value in a SessionScoped bean in my stateless session bean
public void setOperator(final Operator operator) {
userData.setUid(operator.getId());
开发者_开发问答}
When I try to get the object with @Inject I only get null
@ManagedBean(name = "RoleController")
@SessionScoped
public class RoleController {
...
@Inject
private UserData userData;
...
public UserData getUserData() {
System.out.println("ID");
System.out.println(userData.getUid());
I have a bean.xml
Replace
@ManagedBean(name = "RoleController")
with
@Named("RoleController")
and ensure you are importing javax.enterprise.context.SessionScoped and not javax.faces.bean.SessionScoped for both of your classes.
精彩评论