2

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

Community
  • 1
  • 1
Sebastian Wramba
  • 10,087
  • 8
  • 41
  • 58

1 Answers1

5

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.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118