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...

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