• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Injecting EJB into a JSF web application

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have an EJB already deployed (on JBoss), and I wish to develop and deploy (to the same app server) a JSF-based web application, what am I supposed to add to my web.xml so that I can use the @EJB annotation to inject EJBs into a managed bean? Is this app server specific?

I hope, you understand my question...

Thanks for your time
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Veggen,
The J2EE spec doesn't not support injecting EJB into regular Java classes. It supports servlets and other EJBs. For JSF managed beans, you would still need to use a JNDI lookup.

It's possible an app server provides a proprietary way of doing this, but I don't know of one.
 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure this applies to Java EE 5 (i.e. JSF 1.2 and EJB 3.0) as well? I'm quite sure I've been seening examples on the web that to this... just not their web.xml and that's the part that troubles me. Of course, I could be wrong.
[ September 14, 2008: Message edited by: Veggen Skrikk ]
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there are JEE 5 examples that do this, such as Duke�s Bank, and without anything particular in the web.xml descriptor file.
 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I've seen that example. The only place EJBs are mentioned is in the application.xml within the <module> element. I figured that's because both EJB and Web' app were deployed as a single EAR. So, I was wandering if anything should be added to web.xml if the EJB has already been deployed separately, but it seems the @EJB annotation is itself enough. If someone could confirm, it would be great.

Also, I keep seeing claims that EJB injection into JSF managed beans is not supported on JBoss but it is supported in SunAS/Glassfish, but I've also seen opposite claims... Any info on this would be useful.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Also, I keep seeing claims that EJB injection into JSF managed beans is not supported on JBoss but it is supported in SunAS/Glassfish, but I've also seen opposite claims... Any info on this would be useful.



As far as I know, JBoss uses Tomcat as Webcontainer. Tomcat doesn't implement the @EJB annotation yet, therefore the @EJB doesn't work in JBoss (even with Servlet it doesn't work). You must use JNDI lookup: Example here
 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for clarifying it!
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jboss supports EJB3.0 annotations, infact there is a book by OREILLY which has all the examples based on Jboss 4.x.x and annotations...
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also suggest all of you to read the book by EJB3.0 in Action by depu panda and then EJB3.0 by OREILLY to understand the correct concepts of EJB3.0 ...
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by aleem khan:
Jboss supports EJB3.0 annotations, infact there is a book by OREILLY which has all the examples based on Jboss 4.x.x and annotations...



JBoss really support EJB3, I did many EJB components on JBoss. You can use @EJB annotation within an EJB component to call another EJB component.
The point here is that you cannot use the @EJB annotation within a Servlet component. It happens because JBoss uses Tomcat as WebContainer and Tomcat doesn't implement that annotation.

Different than Glassfish (or even Geronimo and Websphere) that you can use @EJB annotation within a Servlet component.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried on glassfish its working....

i used... private @EJB(name="SessionLocalBean") SessionLocal dao;

@Stateless
public class SessionLocalBean implements SessionLocal


see if it works... gernimo.....and jboss AS 5cr2
[ September 21, 2008: Message edited by: sameer ravindra ]
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic