webtier@glassfish.java.net

NullPointerException when using _at_ManagedBean or _at_PersistenceUnit in a Phase

From: <webtier_at_javadesktop.org>
Date: Wed, 02 Dec 2009 11:00:11 PST

I have a PhaseListener that I want to use provide authentication to my jsf app.
 I created a PhaseListener class (with a phaseId of PhaseId.RESTORE_VIEW) in
which I want it to use an AuthenticationBean that I created.

1. If I use the following, I get a NullPointer exception:
    @ManagedProperty(value = "#{auth}")
    private AuthenticationBean authService;

2. If I use the following, I DON'T get an exception (everything works fine):
        FacesContext context = FacesContext.getCurrentInstance();
        AuthenticationBean authService =
FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(context.getELContext(),
null, "auth");

If I can use #2 method, shouldn't I be able to use method #1?

I ALSO get a NullPointerException in my PhaseListener class if I try to use the
following:

    @PersistenceUnit(unitName = "MyPU")
    private EntityManagerFactory emf;

Note: Also, If I move the @PersistenceUnit code into my AuthenticationBean class
(and then obtain an instance of this object in my PhaseListener using method #2)
I also get the same NullPointerException.

Note 2: I'm using version 2.0.2-b09 of both jsf-api AND jsf-impl

Am I doing something wrong?
[Message sent by forum member 'jeffcampbell' ]

http://forums.java.net/jive/thread.jspa?messageID=374347