Blogs
The Future is Finally Here
Announcement
On March 2, 2021 Liferay released a new set of Maven archetypes that enable developers to build and deploy "thin" JSF portlet WAR artifacts. In addition, these archetypes enable developers to optionally enable OSGi+CDI Integration.
Background
This post is a follow-up to How to try JSF thin WAR demo portlets.
The Future is Finally Here
Back on Nov 23, 2016 I presented a session at Liferay DEVCON titled Developing WABs With a View to the Future. Although it took 4 1/2 years, these archetypes represent the fulfillment of a promise made during that session. Specifically, developers can now deploy "thin" JSF portlet WAR artifacts that optionally enable Contexts and Dependency Injection (CDI). The main reasons for the delay was that CDI integration was undergoing the standardization process, and the first implementation of it didn't appear in Liferay as a feature until January of 2019 with the release of Liferay Portal 7.1.2 CE GA3. Not coincidentally, that was the first release that fully supported JSR 362 (Portlet 3.0) which has CDI requirements. After this release, the Liferay Faces team was able to press forward with JSR 378 (Portlet 3.0 Bridge for JSF 2.2) along with support for "thin" JSF portlet WARs and OSGi+CDI Integration.
What is a "thick" JSF portlet WAR artifact?
Until recently, JSF portlet applications have always been built as a "thick" WAR artifact, meaning the JSF dependencies were embedded inside of WEB-INF/lib. In some cases, this caused WAR artifacts to start out at 12MB in size, even before any custom code was added. For example, with PrimeFaces:
- WEB-INF/lib/javax.faces-2.2.20.jar (3.1 MB)
- WEB-INF/lib/primefaces-8.0.jar (5.4 MB)
- WEB-INF/lib/com.liferay.faces.alloy-4.1.0.jar (600 KB)
- WEB-INF/lib/com.liferay.faces.bridge.api-4.2.0.jar (83 KB)
- WEB-INF/lib/com.liferay.faces.bridge.ext-6.1.0.jar (146 KB)
- WEB-INF/lib/com.liferay.faces.bridge.impl-4.2.0.jar (540 KB)
- WEB-INF/lib/com.liferay.faces.portal-4.1.0.jar (173 KB)
- WEB-INF/lib/com.liferay.faces.util-3.4.0.jar (385 KB)
In order to cut down on some of the size, developers would use Java EE application servers like Glassfish and WildFly which shipped with the JSF implementation (Mojarra) already in the classpath. This worked fine back in the days of Liferay Portal CE/EE 6.2. But when Liferay Portal CE/DXP 7.0 migrated to OSGi, developers lost the ability to use the JSF implementation provided by the application server. This is because with Liferay Portal CE/DXP 7.x, a WAR artifact is transformed upon deployment into Web Application Bundle (WAB). Since WABs are OSGi modules, they participate in the OSGi classpath, and not the classpath provided by application server.
What is a "thin" JSF portlet WAR artifact?
With the release of Liferay Faces Bridge 4.2.0 back on October 24, 2020 it became possible to deploy ALL of the aforementioned JAR artifacts as OSGi modules in $LIFERAY_HOME/osgi/modules. Soon after, I published a blog post titled How to try JSF thin WAR demo portlets. But again, there was no convenient way for developers to learn how to convert their "thick" WAR artifacts into "thin" ones. But now that the archetypes are available, we hope that developers find it convenient and easy.
Again, since of the aforementioned JAR modules can be deployed to $LIFERAY_HOME/osgi/modules, it means that they no longer need to be present in WEB-INF/lib. That's what makes a JSF portlet WAR artifact "thin".
How can I try the archetypes?
We just updated the home page of liferayfaces.org with a new archetype selector. Specifically, there are two new dropdown lists:

The first dropdown list is Format which has two options: Thick/Thin.
The second dropdown list is OSGi+CDI Integration which has two options: Enabled/Disabled.
When you make selections from these dropdown lists, the Maven Build command will update with corresponding Maven profile usage.
What does a project generated from an archetype look like?
The generated project has a very simple "Hello World" type of UI:

And if CDI is enabled, the UI will contain "Greetings from CDI" as well.
Enjoy!

