Reputation: 27
my sessionfacade class
package com.entity;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class UsersFacade extends AbstractFacade<Users> implements UsersFacadeLocal
{
@PersistenceContext(unitName = "My_communityPU")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public UsersFacade() {
super(Users.class);
}
}
my managed bean class
package com.jsf;
import com.entity.Users;
import com.entity.UsersFacadeLocal;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@Named(value = "loginMB")
@ManagedBean
@SessionScoped
public class LoginMB implements Serializable {
@EJB
private UsersFacadeLocal usersFacade;
protected Users user;
protected List<Users> lusers;
protected String username;
protected String password;
public LoginMB() {
lusers=usersFacade.findAll();
}
}
I dont know why my ejb injection in to mangedbean is not working. I am getting null pointer exception when i am calling findall(); method by using usersFacade I am working on netbeans ide with glassfish server. i am just learning jpa in jsf please let me know where i am doing wrong
Upvotes: 0
Views: 1533
Reputation: 2604
Container injects the EJB only after instantiating the managed bean. Use @PostConstruct annotation and use the EJB there. The annotated method will be called after the injection.
Upvotes: 7