我有一个会话范围的bean
@SessionScoped
public class UserData implements Serializable {
private String uid;
public String getUid() {
return uid;
}
public void setUid(final String uid) {
this.uid = uid;
}
我在无状态会话bean
中的SessionScoped bean中设置了一个值public void setOperator(final Operator operator) {
userData.setUid(operator.getId());
}
当我尝试使用@Inject获取对象时,我只得到null
@ManagedBean(name = "RoleController")
@SessionScoped
public class RoleController {
...
@Inject
private UserData userData;
...
public UserData getUserData() {
System.out.println("ID");
System.out.println(userData.getUid());
我有一个bean.xml
答案 0 :(得分:4)
替换
@ManagedBean(name = "RoleController")
与
@Named("RoleController")
并确保您为两个类导入javax.enterprise.context.SessionScoped而不是javax.faces.bean.SessionScoped。