问题
I have the following issue. (jboss 7.1 as, jsf 2 and myFaces extension filter)
Two managed beans. (I have cleaned up the code). I want to retrieve LoginBean from NextBean. The problem is that every time i inject the bean i get a new instance of LoginBean and not the current one. I have tried things like @Named("name"). The bean itself (both) are invoked from the jsf pages and all data is set, but a new instance is injected every time and i cant figure out what i'm doing wrong!!!
@Named
@SessionScoped
public class LoginBean implements Serializable {
private static final long serialVersionUID = -8825740128333470396L;
@EJB private UserDetailDao userDetailDao;
private String description;
public String getDscription() { return description; }
public String submit() {
userDetailDao.doSomething("test");
description = "testing";
return "next.xhtml";
}
}
and the second bean
@Named
@SessionScoped
public class NextBean extends SomeBean implements Serializable {
private static final long serialVersionUID = -4654827059950265300L;
@Inject private LoginBean loginBean;
public String submit() {
String description = loginBean.getDscription();
return "login.xhtml";
}
}
The "Description" is set and i can see it in the jsf page, but i cant access it from NextBean since it injects a new instance every time! But the data is in the session!
:/
Any tips? Thanks in advance!
回答1:
I was naming the beans wrong! and did not use proper @Produces :/
Thanks for your time lads.
来源:https://stackoverflow.com/questions/9610746/inject-is-injecting-a-new-instance-every-time-i-use-it