Liferay OOTB modules can be customized with the OSGI fragment in Liferay 7. In Liferay 6.2 and most of the earlier versions, the customization of Liferay OOTB portlets was done with the help of Hook plugin. Now in Liferay 7, there is an easy way to achieve this. Below we have listed entire process along with a sample use case for extending customized OOTB modules JSPs in Liferay 7:
First OSGI Fragment is created that needs two important configurations listed below:
1. Fragment-Host: It will point to OOTB module’s symbolic name and bundle version number.
2. Customize JSP: Customize JSP which is copy of original JSP and our own changes.
Further steps are being explained with the help of a use case example.
• In the Control Panel -> Web Content, there is “+” icon at the bottom right. Clicking on “+” icon, it will display a popup menu with the list of structure name. By default, it is in ascending order of the creation date. Here we will sort it in ascending order of structure name.
• Find original JSP path in the Liferay source code. It is taglib and located at below path in the portal source.
liferay-src/modules/apps/foundation/frontend-taglib/frontend-taglib/src/main/resources/META-INF/resources/add_menu/page.jsp
• Override the page.jsp and write logic to ascending order for MenuItems i.e. Structure Name.
• Create new MVC module with name like “frontend-taglib-fragment” with Blade CLI or with Liferay IDE.
• Now, to get Fragment host value, look into Liferay source module with below path.
/liferay-dxp-digital-enterprise-src-7-3.0-ga1/modules/apps/foundation/frontend-taglib/frontend-taglib/bnd.bnd
• Open bnd.bnd file and search for Bundle-SymbolicName and find “com.liferay.frontend.taglib” which is the fragment host value in custom module. Also, get the Bundle-Version of the same.
• Go to the custom module frontend-taglib-fragment/bnd.bnd and copy above detail as below:
Fragment-Host: com.liferay.frontend.taglib;bundle-version=“2.0.3″
• Copy page.jsp from Liferay source and add in custom module. Please note that it is necessary to follow the same folder structure as in Liferay source. So, create add_menu folder inside “frontend-taglib-fragment/src/main/resources/META-INF/resources” and paste page.jsp from Portal source.
• Now do the requied changes in custom jsp. In order to get the ascending of menu items, add below code before iteration of for loop of Menu Items.
Collections.sort(addMenuItems, new Comparator() { public int compare(AddMenuItem arg1, AddMenuItem arg2) { return arg1.getLabel().compareTo(arg2.getLabel()); // Compare by label }});
• Deploy “frontend-taglib-fragment”.
• If the module is deployed successfully then you should get structure name in ascending order.
This is how with the help of OSGI Fragment, we can create override OOTB modules JSPs in Liferay 7.
If you still have any query regarding OSGI Fragment or overriding OOTB modules JSPs in Liferay 7, you can discuss with our Liferay consultant!