There are several different ways to customize JSPs in portlets and the core. Liferay Portal’s API provides the safest ways to customize them. If you customize a JSP by other means, new versions of the JSP can render your customization invalid and leave you with runtime errors. It’s highly recommended to use one of the API-based ways.

Using Liferay Portal’s API to Override a JSP

Here are API-based approaches to overriding JSPs in Liferay Portal:

Approach Description Cons/Limitations
Dynamic includes Adds content at dynamic include tags. Limited to JSPs that have dynamic-include tags (or tags whose classes inherit from IncludeTag). Only inserts content in the JSPs at the dynamic include tags.
Portlet filters Modifies portlet requests and/or responses to simulate a JSP customization. Although this approach doesn’t directly customize a JSP, it achieves the effect of a JSP customization.

Overriding a JSP Without Using Portal’s API

It’s strongly recommended to customize JSPs using Liferay Portal’s API, as the previous section describes. As of Liferay 7.0, overriding a JSP using an OSGi fragment or a Custom JSP Bag are both deprecated. Since these approaches are not based on APIs there’s no way to guarantee that they’ll fail gracefully. Instead, if your customization is buggy (because of your code or because of a change in Liferay), you are most likely to find out at runtime, where functionality breaks and nasty log errors greet you.

If you’re maintaining a JSP customization that uses one of these approaches, you should know how they work. This section describes them and links to their tutorials.

Here are ways to customize JSPs without using Liferay Portal’s API:

Approach Description Cons/Limitations
OSGi fragment (deprecated as of Liferay 7.0) Completely overrides a module’s JSP using an OSGi fragment Changes to the original JSP or module can cause runtime errors.
Custom JSP bag (deprecated as of Liferay 7.0) Completely override a Liferay Portal core JSP or one of its corresponding -ext.jsp files. For Liferay Portal core JSPs only. Changes to the original JSP or module can cause runtime errors.

All the JSP customization approaches are available to you. It’s time to customize some JSPs!

Customizing JSPs with Dynamic Includes

The liferay-util:dynamic-include tag is an extension point for inserting content (e.g., JavaScript code, HTML, and more). To do this, create a module that has content you want to insert, register...

Read More

JSP Overrides Using Portlet Filters

Portlet filters let you intercept portlet requests before they’re processed and portlet responses after they’re processed but before they’re sent back to the client. You can operate on the request...

Read More

JSP Overrides Using OSGi Fragments

You can completely override JSPs using OSGi fragments. This approach is powerful but can make things unstable when the host module is upgraded: By overriding an entire JSP, you might not account...

Read More

JSP Overrides Using Custom JSP Bag

Liferay’s API based approaches to overriding JSPs are the best way to override JSPs in apps and in the core. You can also use Custom JSP Bags to override core JSPs. But the approach is not as...

Read More
-1 (1 Vote)
Customizing Previous