JSF 1.2 - Resource Injection for classes other than managed beans

I'm trying to get an EJB resource in a JSF converter, but the dependancy injection only seems to work with managed beans (see recent article http://java.sun.com/developer/technicalArticles/J2EE/injection/index.html).

Simply creating a instance of a managed bean with a normally working resource injection , then getting a reference to that resource results in a null value. This I can understand because the JSF life-cycle at that point isn't geared up for a managed bean.

So the question is this - anybody know a way to get a resource reference using dependancy injection for converter/render kit etc via a managed bean? I realise I could just do an "old" JNDI lookup in the converter but I wondered if there was a better solution in JEE5

Cheers

Dan

[783 byte] By [daniel.rhoadesa] at [2007-10-3 0:01:51]
# 1

Mmmmm ... try it:

FacesContext fc = FacesContext.getCurrentInstance();

MyManagedBean mb = (MyManagedBean) fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "mymanagedbean");

MyEJBRemote ejb = mb.getMyEJB();

MyManagedBean have the EJB inyected, getMyEJB just return the instance.

Maybe work, however i'm not sure.

Rulasa at 2007-7-14 16:49:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Ah yes that would work... just get the ManagedBean from the ELResolver.Cheers
daniel.rhoadesa at 2007-7-14 16:49:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Why not trying having your converter defined as a managed bean? You can pass this to the converter attribute on relevent tags (input tags and the like).
rlubkea at 2007-7-14 16:49:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Tried that first of all :) Didn't work though, I think it's in the wrong life-cyle phase to do that, somebody may correct me though...
daniel.rhoadesa at 2007-7-14 16:49:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Hmm, I'll give it a try here locally and post the results.
rlubkea at 2007-7-14 16:49:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...