Customizing JSPs

There are several different ways to customize JSPs in portlets and the core. Liferay DXP’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’s API to Override a JSP

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

ApproachDescriptionCons/Limitations
Dynamic includesAdds 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 filtersModifies 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 Liferay’s API

It’s strongly recommended to customize JSPs using Liferay DXP’s API, as the previous section describes. Since overriding a JSP using an OSGi fragment or a Custom JSP Bag is 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. These approaches should only be used as a last resort.

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 DXP’s API:

ApproachDescriptionCons/Limitations
OSGi fragmentCompletely overrides a module’s JSP using an OSGi fragmentChanges to the original JSP or module can cause runtime errors.
Custom JSP bagCompletely override a Liferay DXP core JSP or one of its corresponding -ext.jsp files.For Liferay DXP 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!

« Introduction to CustomizingCustomizing JSPs with Dynamic Includes »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています