开发者

@Named behaving different from @ManagedBean

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜