Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Would you ever use injection for referencing an EJB in a JSF managed bean?  RSS feed

emanuel petre
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people here said that the ServiceLocator is not anymore needed in EJB 3 because of the new way of injecting dependencies trough annotations.
This can be true in case of EJB -> EJB dependency. But, in case you want to call an EJB from the web tier, you still need to use a Service Locator. First,
you have the possibiltiy to inject an EJB by using annotations in the web components managed by server (like ServletListener or a JSF managed bean).
But, this way you expose the business tier directly to the presentation and you strongly couple the two. The only solution, I think, is to use a Business Delegate for abstractizing the business to the presentation. The Business Delegate will not be a component managed by the container. As a consequence, you cannot use injection in this case and you need a Service Locator.

That's why I think, the EJB injection shouldn't be used in a JSF managed bean.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!