Skip to main content

accessing EJB which is also a JSF managed bean from JSF xhtml file

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2007-04-16

what is the right way to use a jsf xhtml page to access an ejb which is also a managed bean for JSF ?

in the javaee6tutorial trunk download at

in example jaxrs/Customer they have 2 beans.
a CustomerManager bean annotated @Stateful @Named
and a CustomerBean annotated @Named @Stateless.

The index.xhtml jsf page accesses #{customerManager.customer.firstname} and other fields.

But each time the #{customerManager.customer.xxxx} expression is evaluated a new Customer is created in the
    private void init() {"new customer created");
        customer = new Customer();
of the class.

-- instead of creating 1 time and then accessing the same bean for the other expression language statements in the file.

It seems as if the Scoping is messed up.

All the examples i have seen previously use a managed bean(JSF or JavaEE) that then accesses an EJB located in another class.

What is the proper way to use a single class as an ejb and a jsf managed bean with scoping in the same class.

Is there documentation that can help explain ? 

Also when to use javax.enterprise.context.RequestScoped vs javax.faces.bean.RequestScoped , ... etc.