0

This was asked in a previous question (http://stackoverflow.com/questions/6043259/auto-instantiate-a-session-bean). I implemented the solution offered by BalusC but it isn't working. This is my code:

@ManagedBean
@SessionScoped
public class UserSessionBean {

AND

@ManagedBean
@ViewScoped
public class ReaderBean implements Serializable {

@ManagedProperty("#{userSessionBean}")
private UserSessionBean userSessionBean;

If I understand BalusC correctly, JSF should auto-instantiate the session bean. In my case I get error saying that ReaderBean cannot be instantiate because no instance of UserSessionBean exists. So how can I get JSF to manage the instantiation for me? Manually instantiating and putting to the session map is supposedly a hack/workaround, so I'd like to avoid it.

Matthew Oakley
  • 507
  • 1
  • 6
  • 15
  • In the future, read the stacktrace from bottom to top. The bottommost part is the firstmost root cause. That part should already have hinted you about a missing setter. – BalusC Oct 08 '12 at 19:17

1 Answers1

1

I got the answer.

The Managed Property required Getter and Setter methods.

Matthew Oakley
  • 507
  • 1
  • 6
  • 15
  • Indeed, but `@ManagedProperty` only needs a setter to do the injection. The getter is to obtain it from its holding bean either in a page or another class/bean. – Fritz Oct 08 '12 at 13:41