Could anyone help me? There is a SessionScoped Managed Bean and one Stateless Ejb and one other Stateful Ejb..
The serachCustomer() method in the MB call the injected DaoEjbTst searcCustomer() method which return with an instance of BCus entity object. I injected in to Stateless DaoEjbTst Ejb the other Stateful CustomerSession EJB and when the entity instance is ready in the DaoEjbTst EJB i call the CustomerSession EJB setActualCustomer method and i give as paramter the entity instance for this method and try to store it... Then when i try to get this "stored" entity instance with another showTstDate() method in the ManagedBean it's throws NullPointer Exception.. And i dont know why.. Why doesn't exist the public BCus actualCustomer paramter in the stateful ejb? I tryed to create @PreDestroy and @PrePassivate and @Remove methods in the Stateful Ejb to check if the container remove it but this methods never invoked by the container.. So i'm sure the ejb exist.. but inspite of this i can't access it :( I don't use interfaces.
Here is my managedbean:
@EJB
private DaoEjbTst daoEjb;
@EJB
private CustomerSession customerSession;
public void serachCustomer() throws IOException {
FacesContext ctx = FacesContext.getCurrentInstance();
if (daoEjb.searcCustomer(custNo)) {
ctx.getExternalContext().redirect("showCustomer.xhtml");
}
else {
ctx.getExternalContext().redirect("test.xhtml");
}
}
public String showTstDate() {
log.info("MB EJB EXIST: " + customerSession);
return "Test: " + customerSession.getActualCustomer().getCustName();
}
Here is my DaoEjbTst:
@Stateless
public class DaoEjbTst {
private final Logger log = Logger.getLogger("DaoEjbTst.class");
@EJB
private CustomerSession customerSession;
public CustomerSession getCustomerSession() {
return customerSession;
}
public void setCustomerSession(CustomerSession customerSession) {
this.customerSession = customerSession;
}
@PersistenceContext(unitName = "TestAppPU")
private EntityManager em;
public boolean searcCustomer(String custNo) {
try {
BCus cus = (BCus) em.createNamedQuery("BCus.findByCustomerno").setParameter("customerno", custNo).getSingleResult();
log.info("DAOEJB: " + cus);
customerSession.setActualCustomer(cus);
return true;
}
catch (NoResultException e) {
log.info(e.getMessage());
return false;
}
}
And here is my CustomerSession EJb:
@Stateful
public class CustomerSession {
public BCus actualCustomer;
private final Logger log = Logger.getLogger("CustomerSession.class");
public BCus getActualCustomer() {
return actualCustomer;
}
public void setActualCustomer(BCus actualCustomer) {
this.actualCustomer = actualCustomer;
checkTst();
}
public CustomerSession() {
}
}