Skip to end of metadata
Go to start of metadata

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.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 03, 2013

    Raw content imported to Enterprise docs upto V6

  2. Sep 11, 2013

    Enterprise docs updated to include the note for 6.1 GA

    Development Guide -> Chapter GenericPortlet and Portlet Filter Injection