Struts is a stable, widely adopted framework that implements the Model View Controller (MVC) design pattern. If you have a Struts portlet for Liferay Portal 6.2, you can upgrade it to Liferay Portal CE 7.0.

Upgrading Struts portlets to Liferay Portal CE 7.0 is easier than you might think. Liferay Portal lets you continue working with Struts portlets as Java EE web applications. On deploying a Struts portlet Web Application aRchive (WAR), Liferay Portal’s Web Application Bundle (WAB) Generator creates an OSGi module (bundle) for the portlet and installs it to Liferay’s OSGi framework. The Struts portlet behaves just as it did in 6.2 on your Liferay Portal CE 7.0 site.

This tutorial demonstrates how to upgrade a portlet that uses the Struts 1 Framework and refers to Liferay’s Sample Struts portlet (Sample Struts) as an example. Sample Struts uses several Struts features to show page navigation, Action and ActionForm Controller classes, exceptions, and more.


Figure 1: The Sample Struts portlet’s charts compare fictitious soft drink survey results.

Here are the sample portlet’s characteristics:

  • Model class (Book)
  • View comprised of JSPs that leverage Struts tag libraries
  • Action classes (Controllers) for handling requests and responses
  • ActionForm classes for interacting with models and forwarding requests to Actions
  • Visual component reuse with Tiles
  • Internationalization using Action Messages and resource bundles
  • Form validation using the Validator Framework
  • Error management through Action Errors

You can follow this tutorial to upgrade your Struts portlet. Along the way, you can examine the Sample Struts portlet source code from before and after its upgrade:

Here’s the Sample Struts portlet’s folder structure:

  • sample-struts-portlet
    • docroot/
      • html/portlet/sample_struts_portlet/ → JSPs
      • WEB-INF/
        • lib/ → Required third-party libraries unavailable in the Liferay Portal system
        • src/
          • com/liferay/samplestruts/model/ → Model classes
          • com/liferay/samplestruts/servlet/ → Test servlet and servlet context listener
          • com/liferay/samplestruts/struts/
            • action/Action classes that return View pages to the client
            • form/ActionForm classes for model interaction
            • render/Action classes that present additional pages and handle input
            • → Exception class
          • content/test/ → Resource bundles
          • META-INF/ → Javadoc
        • tld/ → Tag library definitions
        • liferay-display.xml → Sets the application category
        • → Sets metadata and portal dependencies
        • liferay-portlet.xml → Maps descriptive role names to roles
        • → (internal) Release properties
        • portlet.xml → Defines the portlet and its initialization parameters and security roles
        • struts-config.xml → Struts configuration
        • tiles-defs.xml → Struts Tile definitions
        • validation.xml → Defines form inputs for validation
        • validation-rules.xml → Struts validation rules
        • web.xml → Web application descriptor
    • build.xml → Apache Ant build file

Upgrading a Struts portlet involves these steps:

  1. Adapt the code to Liferay Portal CE 7.0’s API

  2. Resolve dependencies

Adapting the code to Liferay Portal 7.0’s API

Liferay’s Code Upgrade Tool identifies code affected by the new API, explains the API changes and how to adapt to them, and in many cases, provides options for adapting the code automatically.

Adapting the Sample Struts portlet’s code is straightforward. Resolving its dependencies is more involved.

Resolving dependencies

The Liferay Portal 6.2 Sample Struts portlet depends on Liferay Portal to provide required third-party libraries and tag library definitions (TLDs). The portal-dependency-jars and portal-dependency-tlds properties in the portlet’s specifies them:



Resolving the tag libraries is easy.

Resolving Tag Library Definitions

Liferay Portal CE 7.0 continues to provide many of the same TLDs Liferay Portal 6.2 provided.

If the Liferay Portal CE 7.0 application’s WEB-INF/tld folder contains a TLD you need, add it to your portlet’s portal-dependency-tlds property in the file. If the folder doesn’t contain the TLD, find the TLD on the web, download it, and add it to your portlet’s WEB-INF/tld folder.

Resolving Third-Party Libraries

Third-party libraries listed as portal-dependency-jars in a 6.x portlet’s file might not be provided by Liferay Portal CE 7.0. Providing fewer libraries streamlines Liferay Portal. Liferay Portal has replaced some of its libraries with newer ones.

Liferay Portal CE 7.0 exposes (exports) Java packages instead of sharing JAR content wholesale. If you need packages Liferay Portal doesn’t export, you can find and download the artifact (JAR) that provides them and add it to your portlet’s docroot/WEB-INF/lib folder.

Here are steps for resolving the Sample Struts portlet’s Java package dependencies:

  1. Liferay Portal doesn’t export Antlr packages. Replace the portlet’s JAR file antlr2.jar with newer JAR antlr.jar from Maven Central.

  2. Liferay Portal doesn’t export packages from portals-bridges.jar. Replace the portlet’s JAR file portals-bridges.jar with these JARs from Maven Central:

    • portals-bridges-common.jar
    • portals-bridges-struts.jar
  3. Liferay Portal doesn’t export packages from struts.jar. Replace the portlet’s JAR file struts.jar with the following ones from Maven Central:

    • struts-taglib.jar
    • struts-tiles.jar
  4. The Import-Packages heading in the com.liferay.portal.bootstrap module’s system.packages.extra.bnd file lists the following JAR files Sample Struts requires. Since the bootstrap module exports packages from these JARs, add their names to the portal-dependency-jars property in the portlet’s file. :

    • commons-beanutils.jar
    • commons-collections.jar
    • commons-lang.jar
  5. Add all the rest of the JARs the Sample Struts portlet depends on to the portlet’s WEB-INF/lib folder.

The following table summarizes the sample portlet’s Java dependency resolution.

Sample Struts Portlet’s Dependency Resolution:

JAR System exports the packages the
portletneeds from this JAR?
antlr.jar No add to WEB-INF/lib
commons-beanutils.jar Yes List in portal-dependency-jars
commons-collections.jar Yes List in portal-dependency-jars
commons-digester.jar No add to WEB-INF/lib
commons-fileupload.jar No add to WEB-INF/lib
commons-io.jar No add to WEB-INF/lib
commons-lang.jar Yes List in portal-dependency-jars
commons-validator.jar No Add to WEB-INF/lib
jcommon.jar No Add to WEB-INF/lib
jfreechart.jar No Add to WEB-INF/lib
oro.jar No Add to WEB-INF/lib
portals-bridges-common.jar No Add to WEB-INF/lib
portals-bridges-struts.jar No Add to WEB-INF/lib
struts-core.jar No Add to WEB-INF/lib
struts-extras.jar No Add to WEB-INF/lib
struts-taglib.jar No Add to WEB-INF/lib
struts-tiles.jar No Add to WEB-INF/lib

For more details on resolving dependencies, see the tutorial Resolving a Plugin’s Dependencies.

You’ve resolved the Sample Struts portlet’s dependencies. It’s ready to deploy.

Deploy the Struts portlet as you normally would. The server prints messages indicating the following portlet status:

  • WAR processing
  • WAB startup
  • Availability to users

Deploying the Sample Struts portlet produces these messages:

00:15:20,344 INFO  [][AutoDeployDir:252] Processing sample-struts-portlet-
00:15:26,871 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][BaseAutoDeployListener:42] Copying portlets for C:\portals\liferay-dxp-digital-enterprise-7.0-sp1\tomcat-8.0.32\temp\20170727241526847GURDCOLU\sample-struts-portlet-
00:15:27,282 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][BaseDeployer:863] Deploying sample-struts-portlet-
00:15:29,627 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][BaseAutoDeployListener:50] Portlets for C:\portals\liferay-dxp-digital-enterprise-7.0-sp1\tomcat-8.0.32\temp\20170727241526847GURDCOLU\sample-struts-portlet- copied successfully
00:15:29,644 WARN  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][WabProcessor:564] The property "portal-dependency-jars" is deprecated. Specified JARs may not be included in the class path.
00:15:33,123 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][BundleStartStopLogger:35] STARTED sample-struts-portlet_7.0.0.1 [1230]
00:15:34,063 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][HotDeployImpl:226] Deploying sample-struts-portlet from queue
00:15:34,065 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][PluginPackageUtil:1007] Reading plugin package for sample-struts-portlet
00:15:34,106 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][PortletHotDeployListener:201] Registering portlets for sample-struts-portlet
00:15:34,424 INFO  [fileinstall-C:/portals/liferay-dxp-digital-enterprise-7.0-sp1/osgi/war][PortletHotDeployListener:313] 1 portlet for sample-struts-portlet is available for use

The Struts portlet is available on your Liferay Portal instance.

Congratulations on upgrading your Struts portlet to Liferay Portal CE 7.0!

Related Topics

Using the WAB Generator

Using Dependency Management Tools

0 (0 Votes)
Upgrading a Liferay JSF Portlet Previous