The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: How can I debug @EJB annotation failure in JSF managed bean?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Nov 28, 2005 1:07 PM by: ludo
cayhorstmann

Posts: 228
How can I debug @EJB annotation failure in JSF managed bean?
Posted: Nov 28, 2005 10:24 AM
  Click to reply to this thread Reply

I am trying to use the @EJB annotation in a JSF managed bean, like this:

public class PageBean
{
@EJB private ServiceInterface service;
. . .
}

<managed-bean>
<managed-bean-name>pb</managed-bean-name>
<managed-bean-class>elvis.web.PageBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>


but the dependency injection doesn't happen. The PageBean instance is loaded, and the service instance field is null.

I have followed the layout in http://www.netbeans.org/kb/articles/javaee5-hello-world.html, with PageBean.class in a web module and ServiceInterface and ServiceBean in an EJB module. (I also tried putting everything in a web module, and it failed in the same way.)

It will surprise nobody that the failure was completely silent--no log entries, no exceptions.

I am using GlassFish build 28.

Any tips on how to debug this? Or maybe a pointer to a working example (preferably one that is independent of the NetBeans 5 beta)?

Thanks,

Cay

ludo

Posts: 120
Re: How can I debug @EJB annotation failure in JSF managed bean?
Posted: Nov 28, 2005 10:55 AM   in response to: cayhorstmann
  Click to reply to this thread Reply

Hi,
the first thing I would double check is the version used for web.xml: it is 2.4 or 2.5?

I think injection is not processed for 'old' web.xml ad deployment time..
It is a usability issue and we are aware of it. I'll follow up on it.

Now, if your web.xml is using the latest web-app schema (2.5), then we need to look at the entire source code of the app or xml files to see why the injection is not happening.

Thanks,
Ludo

cayhorstmann

Posts: 228
Re: How can I debug @EJB annotation failure in JSF managed bean?
Posted: Nov 28, 2005 11:12 AM   in response to: ludo
  Click to reply to this thread Reply

Indeed, that was the problem.

Since the NetBeans example at http://www.netbeans.org/kb/articles/javaee5-hello-world.html has a wrong schema descriptor for application.xml, I thought it might be useful for others to see the correct descriptors. Here they are:

application.xml:

<application xmlns="http://java.sun.com/xml/ns/javaee" version="5"
xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd">

web.xml:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">



Thanks for the quick response!!!

Cay

ludo

Posts: 120
Re: How can I debug @EJB annotation failure in JSF managed bean?
Posted: Nov 28, 2005 11:23 AM   in response to: cayhorstmann
  Click to reply to this thread Reply

Yes, the netbeans source sample is not good any more with b28:
the application.xml has
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/application_5.xsd">

instead of

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd">

See the little diff between j2ee and javaee!! Might be the reason?

Now, I still believe that deployment backend should warn the user about old style J2EE apps, using annotations that these annotations will not be processed at deployment time...
There is nothing worst than a silent NPE at run time.

We'll fix the sample code.
Ludo

ludo

Posts: 120
Re: How can I debug @EJB annotation failure in JSF managed bean?
Posted: Nov 28, 2005 1:07 PM   in response to: ludo
  Click to reply to this thread Reply

bug
http://www.netbeans.org/issues/show_bug.cgi?id=69495
filed




 XML java.net RSS