@Named behaving different from @ManagedBean

霸气de小男生 提交于 2019-12-22 14:41:04

问题


I'm currently migrating a project from JBoss 4.2.2 to JBoss 6.0.0 and I'm also adding Dependency Injection with CDI and migrate from JSF 1.2 to JSF 2.0. I added a beans.xml file to both the ejb-package, as well as the war-package.

Now I have a xhtml page that uses the managed bean LoginBean.java. The beans had been configured in the faces-config.xml like this:

<managed-bean>
    <description>Sample description</description>
    <managed-bean-name>loginBean</managed-bean-name>
    <managed-bean-class>com.sample.managedbeans.LoginBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

So, at first I removed above configuration and added @ManagedBean @SessionScoped to the class itself. Because I wanted to add CDI to the project, I changed @ManagedBean to @Named (in relation to question 2930889).

Now when I submit the form of the corresponding xhtml, the fields username and password (used in the JSP as #{loginBean.username} ) are null. When I change back to @ManagedBean, it works fine.

Am I missing something here?

Kind regards, Sebastian


回答1:


There are actually two @SessionScoped annotations now in ee6, @javax.faces.bean.SessionScoped which comes from the jsf 2 spec and only works together with @ManagedBean and then there is @javax.enterprise.context.SessionScoped from cdi. My guess is that you are using the jsf annotation, which is ignored by cdi, and so cdi creates a new instance of your bean.



来源:https://stackoverflow.com/questions/6581010/named-behaving-different-from-managedbean

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