Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:03:12+00:00 2026-05-27T18:03:12+00:00

I have an EJB (PersonManager) in the Enterprise Application modul, which injects another EJB

  • 0

I have an EJB (PersonManager) in the Enterprise Application modul, which injects another EJB (Person):

@Stateful
public class PersonManager implements PersonManagerLocal {
    @EJB
    private PersonLocal person;

    @Override
    public void setPersonName(String name) {
        person.setName(name);
    }

    @Override
    public String getPersonName() {
        return person.getName();
    }
}

I want to use the PersonManager EJB in a JSF web app. I define it in the faces-config.xml:

<managed-bean>
    <managed-bean-name>personManager</managed-bean-name>
    <managed-bean-class>ejb.PersonManager</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

The problem is that, the injection of the PersonLocal EJB doesn’t happen. The person property is always NULL. What did I wrong?

But if I inject the PersonManager in a JSF managed bean like this:

@ManagedBean
@RequestScoped
public class Index {
    @EJB
    private PersonManagerLocal personManager;
    ....

IT WORKS. I need the first scenario, please help me 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:03:12+00:00Added an answer on May 27, 2026 at 6:03 pm

    You are mixing the responsibilities of EJBs and JSF managed beans. The faces-config.xml registers only JSF artifacts, such as managed beans and not EJBs. Your registration in faces-config.xml

    <managed-bean>
        <managed-bean-name>personManager</managed-bean-name>
        <managed-bean-class>ejb.PersonManager</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    

    does basically exactly the same as

    @ManagedBean
    @SessionScoped
    public class PersonManager {
        // ...
    }
    

    In other words, you’re registering the class as a JSF managed bean which is available in views by #{personManager}. This does not represent the same instance as is managed by the EJB container. You can and should not use faces-config.xml to register EJBs. There you use the annotations from the javax.ejb package for, such as @Stateless and @Stateful. That’s all you need to register an EJB.

    Actually, registering JSF managed beans in faces-config.xml is an old JSF 1.x way which has in JSF 2.x been replaced by the new @ManagedBean annotation.


    Update the proper approach would be:

    View (the Facelets file):

    <h:form>
        <h:inputText value="#{personManager.person.name}" />
        ...
        <h:commandButton value="Save" action="#{personManager.save}" />
        <h:messages />
    </h:form>
    

    Controller (the JSF managed bean):

    @ManagedBean
    @ViewScoped
    public class PersonManager implements Serializable {
    
        private Person person;
    
        @EJB
        private PersonService personService;
    
        @PostConstruct
        public void init() {
            person = new Person();
        }
    
        public void save() {
            personService.create(person);
            FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage("Person successfully created, new ID is " + person.getId()));
        }
    
        // ...
    }
    

    Model (the JPA entity):

    @Entity
    public class Person implements Serializable {
    
        @Id
        private Long id;
    
        private String name;
    
        // ...
    }
    

    Service (the stateless EJB):

    @Stateless
    public class PersonService {
    
        @PersistenceContext
        private EntityManager em;
    
        public void create(Person person) {
            em.persist(person);
        }
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an EJB: @Stateless(mappedName = MetadataFacade) public class MetadataFacade implements MetadataFacadeRemote { and
I have started learning EJB. I like to know which is best application server
I have a EJB defined as this: package com.foo; @Stateless (mappedName=HelloWorld) public class HelloWorldBean
I have a large application that uses EJB 2.x entity beans (BMP). This is
I have a EJB module in remote Glassfish server and application client in my
To summarize the issue I'm encountering, I have an EJB which uses version A
I'm developing an application on Glassfish 3. I have an EJB that looks like
public class Servlet2Stateless extends HttpServlet { @EJB private HelloUserLocal helloUser; @Override public void doGet(HttpServletRequest
I am facing another problem in my little test-webapp. I have an EJB module
I have a singleton ejb which is getting initialised twice. I have no idea

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.