-
1. Injection in managed bean fails in JBoss AS 6 Final
jaikiran Jan 20, 2011 5:08 AM (in response to johan.ca.andersson)Moved to JSF forum.
-
2. Injection in managed bean fails in JBoss AS 6 Final
ssilvert Jan 20, 2011 8:32 AM (in response to johan.ca.andersson)I don't understand what you are trying to do. You mean you want something to happen during a timeout of the HttpSession? You wouldn't want to do that in a JSF PhaseListener. You would instead use an HttpSessionBindingListener.
Stan
-
3. Re: Injection in managed bean fails in JBoss AS 6 Final
johan.ca.andersson Jan 20, 2011 9:32 AM (in response to ssilvert)Thanks, I'll make sure to refactor that part.
However, I get an NPE in the same bean down the stream as well.
Short example from our source:
A page to navigate between "applications".
<h:commandLink action="#{sessionBean.navigateApplication}" >
JSF backing bean with an injected stateless bean.
public class SessionBean {
@EJB(name = "app/SessionManagerBean/remote")
private SessionManager sm;
public String navigateApplication() {
try {
//sm is null at runtime.
sm.checkPrivilege(null, null);
} catch (Exception x) {
return FAILURE;
}
}
//navigation code left out to keep it brief
}
I've checked the JMX console and JBoss startup logs. The bean is added to the deployment:
2011-01-19 16:03:52,601 INFO [org.jboss.ejb3.deployers.JBossASKernel] persistence.unit:unitName=app.ear/core-ejb.jar#app-ds; Required: Described
2011-01-19 16:03:52,606 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss.ejb:service=EJBTimerService; Required: Described
2011-01-19 16:03:52,613 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss-switchboard:appName=app,module=core-ejb,name=SessionManagerBean; Required: Create
2011-01-19 16:03:52,623 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss-injector:topLevelUnit=app.ear,unit=core-ejb.jar,bean=SessionManagerBean; Required: Described
2011-01-19 16:03:52,633 INFO [org.jboss.ejb3.deployers.JBossASKernel] and supplies:
2011-01-19 16:03:52,640 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:app/SessionManagerBean/local
2011-01-19 16:03:52,645 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:app/SessionManagerBean/local-com.app.common.session.SessionManagerLocal
2011-01-19 16:03:52,651 INFO [org.jboss.ejb3.deployers.JBossASKernel] Class:com.app.common.session.SessionManagerRemote
2011-01-19 16:03:52,657 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:SessionManagerBean
2011-01-19 16:03:52,663 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:app/SessionManagerBean/remote
2011-01-19 16:03:52,668 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:app/SessionManagerBean/remote-com.app.common.session.SessionManagerRemote
2011-01-19 16:03:52,674 INFO [org.jboss.ejb3.deployers.JBossASKernel] Class:com.app.common.session.SessionManagerLocal
2011-01-19 16:03:52,684 INFO [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:ear=app.ear,jar=core-ejb.jar,name=SessionManagerBean,service=EJB3) to KernelDeployment of: core-ejb.jar
Is it impossible to use dependency injection to lookup beans located in one jar from JSF backing beans located in another jar if both jars are located in the same ear?
-
4. Re: Injection in managed bean fails in JBoss AS 6 Final
valliman Feb 11, 2011 12:49 PM (in response to johan.ca.andersson)Hello,
I have somehow the same problem. Our project looks like the following.
web-app project:
containing jsf managed beans
connector project:
contains interfaces of our ejbs and common beans who are needed on server and client side
server project:
contains the implementations of our EJB interfaces and business logic
We package like the following.
WAR including web-app project and connector as lib
EAR including server-project as ejb module and the connector as jar
Our code looks like the one specified below.
@Managed
@SessionScoped
public class ManagedSessionBean {
@EJB(lookup = MyService.mappedName)
MyService service;
}
@Remote
public interface MyService {
public static final String mappedName = "someName";
}
@Stateless(mappedName = MyService.mappedName)
public class MyServiceImpl implements MyService {
}
We get an NPE when accesing the EJB in the web-app jsf managed bean. However as mentioned before lookup with InitialContext is working as expected.
I've also tried to specify no mappedName, however injection with the JNDI name provided by JBoss isn't working either.
Is this a JBoss 6 Final bug, or I am just doing something wrong?
-
5. Re: Injection in managed bean fails in JBoss AS 6 Final
feichtegger Apr 20, 2011 2:08 AM (in response to johan.ca.andersson)As far as I understand your problem I think I've a kind of the same issue.
I also try to inject an EJB reference using the @EJB annotation into a JSF backing bean.
If I declare the bean using the @ManagedBean annotation the reference is null.
If I use the CDI compliant @Named annotation the EJB will referenced correctly.
Unfortunately some other JSF behavior will be lost when I'm using the @Named annotation - the bean properties will not be set as excpected.
So my question is, what is the state of your problem. Have you found a solution? Have you created a JIRA issue?
kind regards
Michael
-
6. Injection in managed bean fails in JBoss AS 6 Final
jaikiran Apr 19, 2011 2:38 PM (in response to feichtegger)What else does your ear contain? Are you packaging any jar(s) containing javax.ejb.* classes? Can anyone of you attach a simple application here?
-
7. Re: Injection in managed bean fails in JBoss AS 6 Final
feichtegger Apr 20, 2011 2:11 AM (in response to jaikiran)I deploy war which contains the JSF application and a few EJB's packaged in a separate jar files.
I'm trying to extract a sample out of my project and provide it.
-
8. Re: Injection in managed bean fails in JBoss AS 6 Final
jaikiran Apr 20, 2011 2:21 AM (in response to feichtegger)Michael Feichtegger wrote:
I deploy war which contains the JSF application and a few EJB's packaged in a separate jar files.
The .war and EJB jars are deployed separately and not part of an .ear?
Michael Feichtegger wrote:
I'm trying to extract a sample out of my project and provide it.
Yeah, that would help.
-
9. Re: Injection in managed bean fails in JBoss AS 6 Final
feichtegger Apr 20, 2011 7:04 AM (in response to feichtegger)During preparing the example I discovered the problem.
I used @LocalBean annotations to declare the EJB without a @Local interface class.
In the backing bean I used @EJB to get a reference. When using @ViewScoped JSF serializes the bean and I got an Exception. So I decided to declare the EJB transient which causes a NullPointerException.
Finally I declared an interface and annotated it with @Local and used
@EJB(name="HelloServiceBean", beanInterface="HelloService")
private HelloService service;
works as expceted.