Skip to end of metadata
Go to start of metadata

It may be necessary at times to manually obtain instances of beans managed by Errai IOC from outside the container managed scope or creating a hard dependency from your bean. Errai IOC provides a simple client-side bean manager for handling these scenarios: org.jboss.errai.ioc.client.container.ClientBeanManager.

As you might expect, you can inject a bean manager instance into any of your managed beans. If you use Errai IOC in its default mode you will need to inject the synchronous bean manager (org.jboss.errai.ioc.client.container.SyncBeanManager).

If you have asynchronous IOC mode enabled simply inject the asynchronous bean manager (org.jboss.errai.ioc.client.container.async.AsyncBeanManager) instead. Asynchronous IOC brings support for code splitting. That means that any bean annotated with @LoadAsync can be compiled into a separate JavaScript file that's downloaded when the bean is first needed on the client.

Injecting the client-side bean manager

If you need to access the bean manager outside a managed bean, such as in a unit test, you can access it by calling org.jboss.errai.ioc.client.container.IOC.getBeanManager()

Looking up beans

Looking up beans can be done through the use of the lookupBeans() method. Here's a basic example:

Example lookup of a bean

In this example we lookup a bean class named SimpleBean. This example will succeed assuming that SimpleBean is unambiguous. If the bean is ambiguous and requires qualification, you can do a qualified lookup like so:

Looking up beans with qualifiers

In this example we manually construct instances of qualifier annotations in order to pass it to the bean manager for lookup. This is a necessary step since there's currently no support for annotation literals in Errai client code.

Availability of beans

Not all beans that are available for injection are available for lookup from the bean manager by default. Only beans which are explicitly scoped are available for dynamic lookup. This is an intentional feature to keep the size of the generated code down in the browser.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.