1

I would like to know if the approach I am following is the correct one and in that case how to solve the following causality.

I have a ManagedBean application for the distributed access of the NOSQL connections with the BD and a DAO that is responsible for managing the connections and their maintenance (here the @ManagedProperty bean is injected).

The problem arises when calling the dao to obtain the NOSQL connection, when making a new (...) the bean is not initialized since it needs to be initialized within the life cycle of JSF.

What would be the right approach?

@ApplicationScoped
@ManagedBean
public class FactoriaMongoDAO extends FactoriaDAO {

    @ManagedProperty(value = "#{mongoConnector.client}")
    MongoClient mongoClient;
public class xx{
 FactoriaDAO.getInstancia().getPatientPlayerDAO();
}
@ManagedBean
public abstract class FactoriaDAO {
  private static FactoriaDAO unicainstancia = null;

    public FactoriaDAO(){}

    public static FactoriaDAO getInstancia() {
        if (unicainstancia == null) unicainstancia = new FactoriaMongoDAO( "xx");
        return unicainstancia;
    }  
        public abstract PatientPlayerDAO getPatientPlayerDAO();
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Diego
  • 13
  • 5

0 Answers0