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.

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top