<dependency> <groupId>org.gatein</groupId> <artifactId>cdi-portlet-integration</artifactId> <version>1.0.3.Final</version> </dependency>
There are a couple of steps to enabling CDI for JSF2 portlets that use Portlet Bridge.
This is only required when deploying to servers that use CDI 1.0
First is to add the following dependency to your pom.xml to add the portlet integration library for CDI:
<dependency> <groupId>org.gatein</groupId> <artifactId>cdi-portlet-integration</artifactId> <version>1.0.3.Final</version> </dependency>
When deploying to GateIn, the portlet integration library for CDI is automatically included for JSF2 portlets that use CDI.
So we need to ensure the dependency is marked as provided in our pom.xml:
<dependency> <groupId>org.gatein</groupId> <artifactId>cdi-portlet-integration</artifactId> <version>1.0.3.Final</version> <scope>provided</scope> </dependency>
If you still want to include the CDI integration library in your application you can disable the automatic inclusion of it. This could, for example, be useful if you need to use a different version of the CDI integration library.
To do that, just specify the org.gatein.cdi.DISABLE_CDI_INTEGRATION context param in your web.xml file like this:
<context-param> <param-name>org.gatein.cdi.DISABLE_CDI_INTEGRATION</param-name> <param-value>true</param-value> </context-param>
Add the following portlet filter definition into your portlet.xml so that Portlet Request objects are wrapped appropriately for CDI usage:
<filter> <filter-name>PortletCDIFilter</filter-name> <filter-class>org.gatein.cdi.PortletCDIFilter</filter-class> <lifecycle>ACTION_PHASE</lifecycle> <lifecycle>EVENT_PHASE</lifecycle> <lifecycle>RENDER_PHASE</lifecycle> <lifecycle>RESOURCE_PHASE</lifecycle> </filter>
Then add to portlet.xml the activation of the above filter for each portlet that requires CDI:
<filter-mapping> <filter-name>PortletCDIFilter</filter-name> <portlet-name>[Name of your portlet as defined in portlet-name]</portlet-name> </filter-mapping>
If you need to also wrap Portlet Response objects, then use the org.gatein.cdi.PortletCDIResponseFilter instead.
The default is now to not wrap multipart requests with any Http wrapper. If you need to have multipart requests wrapped so that they can be used with CDI, you can re-enable the wrapping by adding an init-param for org.gatein.cdi.ENABLE_MULTIPART_REQUEST_WRAPPING to the portlet filter definition in portlet.xml, such as:
<filter> <filter-name>PortletCDIFilter</filter-name> <filter-class>org.gatein.cdi.PortletCDIFilter</filter-class> <lifecycle>ACTION_PHASE</lifecycle> <lifecycle>EVENT_PHASE</lifecycle> <lifecycle>RENDER_PHASE</lifecycle> <lifecycle>RESOURCE_PHASE</lifecycle> <init-param> <name>org.gatein.cdi.ENABLE_MULTIPART_REQUEST_WRAPPING</name> <value>true</value> </init-param> </filter>