JBoss Community Archive (Read Only)

GateIn Portal 3.8

GenericPortlet and Portlet Filter Injection

For portlet applications, CDI is activated in the very same way as for any other application: a WEB-INF/beans.xml file needs to be present inside the WAR, as defined by the JSR 299 specification. There are no additional configurations required to use CDI within your portlet or portlet filter.

Any portlet class extending GenericPortlet or implementing Portlet interface, and any portlet filter class implementing PortletFilter, RenderFilter, ActionFilter, EventFilter or ResourceFilter, is able to have CDI beans injected into it, even though it is not directly managed by the CDI container. Just as with any kind of injection, its only a matter of using @Inject and the type of the bean you want to have injected.

At the point at which the injection is performed on the portlet class or filter some contexts will not be active, such as session, which will cause ContextNotActiveException to appear if that context is relied upon. Such a situation could arise if the bean being injected is produced by a bean that is in session scope.

Example Code

There is CDI Generic Portlet example available in our Quickstarts Collection with a basic portlet and portlet filter using CDI. Another quickstart therein, CDI Portlet with JSF, shows the usage of CDI in combination with JSF.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 13:19:34 UTC, last content change 2013-06-19 13:28:14 UTC.