no

How to create an instance bean in JavaEE using its class

JavaEE6 has really revolutionize the development using CDI (from seam) but there are times when we need to create an instance of a class not...

JavaEE6 has really revolutionize the development using CDI (from seam) but there are times when we need to create an instance of a class not by injection but by other means such as Component.getInstance from seam.

In seam we have something like
MyClass myClass = (MyClass) Component.getInstance("MyClass");

In JavaEE6, we do that by:
Bean bean = (Bean) beanManager.getBeans(MyClass.class).iterator().next();
CreationalContext ctx = beanManager.createCreationalContext(bean);
return (MyClass) beanManager.getReference(bean, MyClass.class, ctx);


I use this type of approach normally with FacesConverters.

Related

javaee 7483223706328466407

Post a Comment Default Comments

item