views:

195

answers:

3

Even if I have different modules in my jee application including myproject-web and myproject-ejb; is it possible to call (or inject) my ejb session bean which is in the ejb module from a managed bean which is in the web module? When I asked before, I see the following declaration: @EJB private BeanInterface yourbean

However, I wanna learn that whether it is possible or not, to call each other between different contexts (one of it in ejb context, the other one -managed bean- is in web context)?

Any help would be appreciated Best wishes Bariscan

+1  A: 

You can inject an @EJB in a @ManagedBean class, but not the other way round. If you'd like to execute the desired business logic in the EJB class, then you have to pass the managed bean instance as method argument yourselves.

@Local
public class EJB {
    public void process(ManagedBean bean) {
        // Business logic.
    }
}

@ManagedBean
public class ManagedBean {
    @EJB private EJB ejb;

    public void submit() {
        ejb.process(this);
    }
}
BalusC
+1, but I'd be cautious with passing the whole managed bean to the EJB. You can effectively be passing a proxy, which might be irrelevant in an EJB context. + it would most likely be a violation of "the law of Demeter"
Bozho
At first, many thanks for your replies.So, do you mean that I dont have to do jndi lookup to find the ejb session which is in ejb context from a web module?I know if the ejb and managed bean are in the same context, same module (like myProject-ejb) it is possible to inject with @EJB anno. However, I could not find out whether it is possible to inject from different contexts...Do you have any idea about that?Many thanks,Baris
Bariscan
A: 

I could not find a way to do it without jndi lookup yet in JSF v1.2

Bariscan
A: 

If you really want this by all means, i guess you could try to write your own property resolver and inject by yourself(I didn't try).

codeplay

related questions