OmniFaces: Beans.getReference() + qualifier #284

Closed
fkjaekel opened this Issue Jul 7, 2016 · 1 comment

Projects

None yet

2 participants

@fkjaekel
fkjaekel commented Jul 7, 2016

I have the following CDI EntityManager producer:

    @ApplicationScoped
    public class EntityManagerProducer 
    {
        @PersistenceUnit(unitName = MySqlListener.PERSISTENCE_UNIT)
        private EntityManagerFactory    factory;

        @PersistenceUnit(unitName = FirebirdListener.PERSISTENCE_UNIT)
        private EntityManagerFactory    factoryFirebird;

        @Default
        @Produces
        @RequestScoped
        public EntityManager createEntityManager()
        {
            return factory.createEntityManager();
        }

        @Firebird
        @Produces
        @RequestScoped
        public EntityManager createEntityManagerFirebird()
        {
            return factoryFirebird.createEntityManager();
        }
    ...

To lookup a @Firebird EntityManager I have to do this:

        final InitialContext context = new InitialContext();
        final BeanManager bm = (BeanManager) context.lookup("java:comp/BeanManager");

        @SuppressWarnings("unchecked") final Bean<EntityManager> bean = (Bean<EntityManager>) bm.getBeans(//
            EntityManager.class, //
            new AnnotationLiteral<Firebird>()
            {
                private static final long serialVersionUID = 1L;
            })//
            .iterator()//
            .next();//
        final CreationalContext<EntityManager> ctx = bm.createCreationalContext(bean);

        return (EntityManager) bm.getReference(bean, EntityManager.class, ctx);

I'd like to replace this code with Beans.getReference(), but I didn't find a way to inform the @Firebird qualifier.

Could you consider it for a future OmniFaces release?

Thanks

@BalusC BalusC closed this in f81c53f Jul 8, 2016
@BalusC BalusC added a commit that referenced this issue Jul 8, 2016
@BalusC BalusC #284: update javadocs 8b1a431
@BalusC
Member
BalusC commented Jul 8, 2016

That was an oversight. I added them and they are available as per today's latest 2.5-SNAPSHOT.

Thank you for reporting this issue and improving OmniFaces!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment