Monday, 29 June 2015

How to override custom JSP using Liferay Hook

Many a times we like to make a minor changes on the existing OOTB portlet's JSP. Liferay allows to override / modify existing JSP using Hook.

There are three simple steps to achieve it:

1)  Modify "lieray-hook.xml" to provide support for custom jsps (Assuming you have Hook project with JSP Hook created)
2)  Copy the mirror path (JSP name along with folder structure) from  "liferay-portal-[version]/tomcat-6.*/webapps/ROOT"
3)  Deploy and verify changes


Lets look at the steps in detailed:

1)  Modify "lieray-hook.xml" to provide support for custom jsps  (Assuming you have Hook project with JSP Hook created)
    <hook>
        :
        <custom-jsp-dir>/custom_jsps</custom-jsp-dir>
        :
    </hook>
   
    We have specified the custom JSP path inside which all the overridden JSPs will reside
   
2)  Copy the mirror path (JSP name along with folder structure) from  "liferay-portal-[version]/tomcat-6.*/webapps/ROOT"

Lets say we like to override error page which resides inside "webapps\ROOT\errors\404.jsp".

In this case we need to create the folder "errors" inside "/custom_jsps" and copy and paste the 404.jsp file inside "errors".

So after copy our folder structure would look like this "docroot\custom_jsps\errors\404.jsp".
Open the JSP file and make your changes in it.
   
3)  Deploy and verify changes

    Once changes are done we need to deploy our JSP hook project. Once hook is successfully deployed move onto the below path
   
    "liferay-portal-[version]/tomcat-6.*/webapps/ROOT/errors/" and see that now there would be two JSPs.
   
    1)  404.jsp (your overridden changes)
    2)  404.portal.jsp (original JSP)
   
    Note: If you undeploy your JSP hook at that time liferay will delete 404.jsp and rename "404.portal.jsp" with 404.jsp to bring original file back.
   
   
Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

No comments:

Post a Comment