Hooks are commonly used to override web resources, found in the
directory of Liferay’s source. You can use a hook to override JSP files, JSPF
Important: A JSPF change takes effect only when you modify a JSP that includes the JSPF.
Replacing a portal JSP is a simple task with hooks.
Use Liferay IDE to create a new hook project in your Liferay Plugins SDK.
liferay-hook.xmlfile from your project’s
docroot/WEB-INFfolder in Liferay IDE. By default, it opens in Overview mode. This mode gives you a graphical user interface for developing your hook. You can toggle between Overview mode and Source mode via their respective tabs of the
Select the Custom JSPs folder from the outline to bring up the custom JSP options. Select the check box Customize Liferay Portal JSPs and create the default custom JSP folder
/META-INF/custom_jspsby clicking the icon that has the three yellow diamonds.
Add to the listing of custom JSPs by clicking the plus icon and specifying the Liferay Portal JSP file that you want to override. Hint: the browse icon on the right-hand side in the custom JSP text field simplifies finding the JSP you want to customize. It lets you scroll through the accessible JSPs and lets you specify key words to narrow your search.
Open the copy of the Liferay Portal JSP file from the
For example, the custom JSP file copy of Liferay Portal’s
terms_of_use.jspwould be made available in the hook project at
Modify the JSP file with your customization.
Deploy your hook and wait until it is deployed successfully.
The original JSP stays in the cache until the cache is cleared or Liferay Portal is restarted. To clear the cache, navigate to Control Panel → Server Administration and click on the appropriate Clear content … buttons in the Resources tab.
Navigate to the custom JSP in Liferay and verify your customization.
Now there are two JSP files in Liferay deployed on your application server. One
JSP has the original name and the other ends with
.portal.jsp. The first file
is your hook’s version of the file. The
.portal.jsp file is a copy of Portal’s
For example, if the original Portal JSP file was
terms_of_use.jsp, the hook’s
version of the file uses that name and the original version of the file
To revert back to the original, undeploy your hook. Your replacement JSP is
removed, and the
.portal.jsp file is automatically renamed, taking its place.
You can override any JSP in the Liferay core, while retaining thew ability to
revert your changes easily. Be careful not to override the same JSP in multiple
hooks: you’ll get whichever one happened to deploy last.
values for these two properties in
Although this example hook doesn’t provide any new functionality, it demonstrates how to override Liferay’s JSP files.
Congratulations on overriding a Liferay Portal JSP!