JBoss Community Archive (Read Only)

GateIn Portal 3.8

CDI Portlet Development under Tomcat

For GateIn users using Tomcat which does as being a barebones JSP/Servlet container. You’d need to install a CDI implementation which does support working under Tomcat.

In this documentation, we will guide to install Weld - a CDI reference implementation, as Weld documentation is pretty clear and easy to install under Tomcat.

Install Weld in GateIn Tomcat

Perform the following steps:

1. Drop the weld-servlet.jar in Tomcat common library $CATALINA_BASE/lib.

This is an uber JAR of Weld itself, contains both API and Impl. At the time of writing, weld-servlet 1.1.8.Final version is being used.

2. Create /META-INF/context.xml file in webapp's web content with following content (or, if you already have one, add just the <Resource> to it):

<Context>

  <Resource name="BeanManager"
            auth="Container"
            type="javax.enterprise.inject.spi.BeanManager"

            factory="org.jboss.weld.resources.ManagerObjectFactory" />

</Context>

This will register Weld's BeanManager factory in Tomcat's JNDI.

3. Add the following entries to webapp's /WEB-INF/web.xml:

<listener>
   <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

<resource-env-ref>

   <resource-env-ref-name>BeanManager</resource-env-ref-name>

   <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>

</resource-env-ref>


The listener entry basically enables Weld in webapp. The resource entry basically tells webapp to use the BeanManager as available in JNDI.

Portlet CDI scopes

As you know, GateIn has provided two Portlet CDI scope annotations @PortletLifecycleScoped and @PortletRedisplayScoped which support the complex Portlet Lifecycle within CDI. BUT if you want to have them work under Tomcat, you need to add the following listener org.gatein.cdi.contexts.listeners.TomcatCDIServletListener to webapp's /WEB-INF/web.xml

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 13:19:34 UTC, last content change 2014-02-10 12:11:20 UTC.