How to get Messages into static method in Seam 3
-
14-06-2021 - |
Question
In Seam 2 we have a Component.getInstance(someClass), that can be used into static methods to instanciate a bean.
How do I do this aproach in Seam 3?
Ex:
public static someMethod()
{
SomeClass sc = (SomeClass.class) Component.getInstance(SomeClass.class);
...
}
and How I get Messages in static methods?
Update:
I used
BeanManager beanManager = new BeanManagerLocator().getBeanManager();
Bean<?> bean = beanManager.resolve(beanManager.getBeans(SomeClass.class));
SomeClass sc = (SomeClass) beanManager.getReference(bean, SomeClass.class, beanManager.createCreationalContext(bean));
and everything works fine. But all this code have to be written.
Solution
You can query the BeanManager for instances of CDI-beans. This should work in any context, static or not. And it's not Seam 3 specific, BTW
OTHER TIPS
here http://javalabor.blogspot.in/2011/08/our-seam-2-to-jee-6-replacement-list.html you can find the solution .
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow