Calling an EJB from JSF

Java Server Faces (JSF) and Facelets have largely supplemented JSP and permit the use of DI. This simplifies access to the EJB but JNDI can be used if desired. JSF uses the concept of a managed bean to hold business logic. In EJB 3.1 it is not necessary to actually use a managed bean. However, both using an EJB directly and using a managed bean to access an EJB will be presented. Knowing how to use the managed bean approach can be useful especially when reviewing older code.

Getting ready

To access an EJB from a JSF page:

  1. Create a supporting EJB
  2. Annotate the EJB with the @Named annotation

    In this example we will also package the beans in the .war file to demonstrate this new feature of EJB 3.1. Packaging in .war file makes ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.