Overriding Web Resources
Hooks are commonly used to override web resources, found in
Important: A JSPF change takes effect only when you modify a JSP that includes the JSPF.
Use the hook project we created earlier or create a new hook project.
liferay-hook.xml file from your project’s
docroot/WEB-INF folder 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 for the
liferay-hook.xml file’s editor.
Select the Custom JSPs folder from the outline to bring up the custom JSP options. Select the checkbox Customize Liferay Portal JSPs and create the default custom JSP folder
/META-INF/custom_jsps, by clicking the icon that has the three yellow diamonds.
Figure 12.3: Liferay IDE lets you specify a folder for the custom JSPs you’re developing. Create the folder by clicking the icon that has the three yellow diamonds.
Add to the listing of custom JSPs by clicking the plus icon and specifying Portal’s
html/portal/terms_of_use.jsp file. Hint, the browse icon on the right-hand side within the custom JSP text field simplifies finding the JSP you want to customize. It lets you scroll through the JSPs that are accessible and lets you specify key words to narrow your search.
Figure 12.4: Liferay IDE simplifies adding a custom JSP to your hook by providing a powerful overview mode for editing your
Open your hook’s
docroot/META-INF/custom_jsps/html/portal/terms_of_use.jsp file and modify it as necessary.
Note, lots of errors will show in the editor because the resources used in the JSP (e.g.,
PortalUtil) are not available in the project; but they’ll be available from the portal once the hook plugin is deployed to the portal server.
Deploy your hook and wait until it is deployed successfully.
liferay-portal-[version]/tomcat-[tomcat-version]/webapps/ROOT/html/portal directory. One is called
terms_of_use.jsp and another
terms_of_use.jsp is your hook’s version, while
terms_of_use.portal.jsp is the original. 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 easily revert your changes. However, it’s not possible to override the same JSP from multiple hooks; Liferay won’t know which version to use.
Although our example hook doesn’t provide any new functionality, it demonstrates how to override Liferay’s JSP files.
Next, we’ll look at a different way to customize a JSP.