开发者

problem injecting Sessionscoped bean in Managed bean

开发者 https://www.devze.com 2022-12-26 13:45 出处:网络
I have a Session scoped bean @SessionScoped public class UserData implements Serializable { private String uid;

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

精彩评论

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