Share

Customizing JSPs by Extending the Original by Using Hook

We can  replace a existing JSP by HOOK Plugin.But if we want to preserve the existing functionality and add more functionality to existing one also possible by HOOK Plugin.The process is as follows

1. Create a Hook Project
2. Open liferay-hook.xml under docroot/WEB-INF/liferay-hook.xml


 3. Open liferay-hook.xml.You can have the overview of the liferay-hook.xml as follows.In this  
     select Custom Jsps folder from the outline pallet to bring up the custom jsps option


4. 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.By clicking 
    this icon it will create custom_jsps folder under META-INF of our project.It is as follows


5. Now add the existing JSP page of portal which you want to customize by clicking the plus icon(+).
    Here we chosen  blogs/search.jsp


6. This step is important.If you observe the xml file it is not yet saved.So Please save the file by 
     clicking ctrl+s.
7. Replace the JSPs code with the following:

<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@ page import="com.liferay.portal.kernel.util.StringUtil" %>

<liferay-util:buffer var="html">
    <liferay-util:include page="/html/portlet/blogs/search.portal.jsp" />
</liferay-util:buffer>

<%
html = StringUtil.add(
    html,
    "Didn't find what you were looking for? Refine your search and " +
        "try again!",
    "\n");
%>

<%= html %>

8. Notice how this code assigns the original JSP’s HTML content to the variable html. We
    proceed to add some more content of our own to that HTML and then display it.

9. Deploy the hook plugin and add the Blogs portlet to a page.
10. Add a blog and then use the Blog portlet’s search.

Test Case

1. Sign in to the portal
2. Create one page and add Blogs portlet to that page
3. Create one Blog by clicking Add Entry
4. In the top right of Blog Portlet type any blog title which is not created and then click search.
5. Observe the results,it is same as the message given in the search.jsp.it is as below


No comments:

Post a Comment