Our Work

How to Override Taglib (Core JSP) in Liferay 7.X

Updated today

In this article we will discuss how to override Taglib (Core JSP) using Custom JSP Bag in Liferay 7.X.

Steps to follow:

  • Include a class by creating component that implements the CustomJspBag interface

  • Need to register the service in the OSGi runtime.

  • Now Create the JSP in same specified location.

Step 1:  Implementing CustomJspBag:

  • Create a liferay component Class and implement it with the CustomJspBag interface
public class MyCustomJspBag implements CustomJspBag {
}
  • We need to override the following methods in CustomJspBag interface

getCustomJspDir:

        Return the directory path in your module’s JAR where the JSPs are placed (for     example,META_INF/jsps).

getCustomJsps:

        Return a List of the custom JSP URL paths.

gerURLContainer:

        Return a new com.liferay.portal.kernel.url.URLContainer. Instantiate the URL container and override its getResources and getResource methods. The getResource method is for looking up all of the paths to resources in the container by a given path. It should return a HashSet of Strings for the matching custom JSP paths. The getResource method returns one specific resource by its name (the path included)

isCustomJspGlobal:

 Return true

3. On Activating the Component we need to provide the URL of the jsp path

Step 2: Registers the service in OSGI runtime:

Register the custom JSP bag implementation from your module in the OSGi runtime with three properties

context.id:

Specify your custom JSP bag class name.

Eg:MyCustomJspBag

context.name:

 This should be a more human readable name

Eg:My Custom Jsp Bag

Service.ranking:

This will determine the priority of your implementation. If you specify 100 here, and one of your coworkers develops a separate custom JSP bag implementation and gives their a ranking of 101, you’re out of luck. Theirs will take precedence. Logically then, you should use 102

Step 3: Create the JSP in same specified location.

Now Create the jsp which you want to Override in the Custom jsp folder we mentioned in method getCustomJspDir() Method (META-INF/resources)

Include the sources true value in bnd.bnd file as mentioned below

-sources: true

Note:

  • After completion of deployment ,in the server root/html/.. path existed pages will save as actual name.portal.jsp and the updated will be saving as actual name.jsp

  • By undeployment of the module,it is reverting back in server root/html/.. Path

  • actual name jsp pages will be work in the server

Reference Links:

Looking for Liferay Developer?

KTree is the best offshore Liferay development company with extensive experience in Liferay Portal Development services along with Upgrade & Migration. Hire Liferay developers or Liferay development services from LiferayDeveloper.

Request For Quote