Our Work
200+ Enterprises across globally trust KTree for their Web & Mobile application Development needs.See What We Do
Updated today
In this article we will discuss how to override Taglib (Core JSP) using Custom JSP Bag in Liferay 7.X.
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.
public class MyCustomJspBag implements CustomJspBag {
}
Return the directory path in your module’s JAR where the JSPs are placed (for example,META_INF/jsps).
Return a List of the custom JSP URL paths.
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)
3. On Activating the Component we need to provide the URL of the jsp path
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
This should be a more human readable name
Eg:My Custom Jsp Bag
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
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
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:
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.