开发者

problem injecting Sessionscoped bean in Managed bean

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜