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...
https://www.czetsuyatech.com/2013/03/javaee-instance-bean-creation-from-class.html
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
In JavaEE6, we do that by:
I use this type of approach normally with FacesConverters.
In seam we have something like
MyClass myClass = (MyClass) Component.getInstance("MyClass");
In JavaEE6, we do that by:
Beanbean = (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.
Post a Comment