@Inject is injecting a new instance every time i use it

谁都会走 提交于 2020-01-07 02:25:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!