• Liferay JSP Hook Development

    Posted on November 24, 2014 by Hamidul Islam in Liferay.

    Liferay JSP Hook Development


    aimDeveloping JSP Hook is quite  straight forward and this is one of the most easiest hook to create in Liferay Portal. To create a JSP Hook you just need to know which JSP page you want to customize. You should have liferay source code ready to find out the path of JSP page. Once you located the JSP path you are ready to customize.


    Beginners mind storm!!!

    Question 1: How would I know which JSP I need customize?

    Answer: The main purpose of JSP Hook is to customize a specific JSP page. In your project you will be asked to customize a specific part (i.e., JSP) of the portal. For example you are asked to add extra field in Sign In portlet user registration page. Now its your job to find whats the JSP page responsible for user registration page and then customize it.   

    Question 2: I am very new to Liferay Portal. Even I don't know where the user registration jsp available?

    Answer: For the first time it may be little tricky for the beginners.In simple you have to explore it yourself. When you are asked to create any JSP Hook you just try to discover logically whether the JSP that you are going to customize is a part of any portlets or not. Say its part of Sign In Portlet then you look for jsps inside this portlet only.

    Question 3: Do I need to customize always JSP inside JSP Hook?

    Answer: Yes. But you can customize other resources like js files also inside JSP Hook. For beginners its an advance topic.

    Question 4: How many hook do I need to create to customize multiple JSPS?

    Answer: It depends. Say you want to customize 10 different jsp pages from different portlets. All the customization can be done in single hook. But this is not recommended. However if you want to customize 10 JSPs of a particular portlet then do all the customization in a single JSP Hook.  

    Question 5: I customized a JSP by JSP Hook and its deployed. Now I want to roll back my changes to original.

    Answer: Just undeploy the JSP Hook. In simple terms undeploy means go to liferay server and then delete the hook from webapps folder.


    Use Case: In this article I am going customize Liferay sign in Portlet to demonstrate Liferay JSP Hook .

    Before Customization:

    Sign In Portlet before customization

     After Customization:

    Sign In Portlet after customization

    You can notice that after customization Your IP: label is added to the portlet by the hook. How its done? Follow the steps

    Step 1: At first you have to create Liferay plugin project of type Hook. If you don't know how to create it follow the below post

    http://proliferay.com/basics-liferay-hook-development/

    Step 2: Lets consider that we have created Liferay Plugin Project of type hook and the name of the project is sign-in-hook. Inside of this project open liferay-hook.xml and add the below contents

    <?xml version="1.0"?>
    <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">
    
    <hook>
        <custom-jsp-dir>/custom_jsps</custom-jsp-dir>
    </hook>
    

    Note: By this we are just saying that our customization folder is custom_jsps under docroot of the project.

    Step 3: In our case we need to customize liferay original jsp file in the path  \liferay-portal-src-6.2.0-ce-ga1\portal-web\docroot\html\portlet\login\login.jsp. To customize it copy this file to sign-in-hook as shown in below

    directory structure

    Remember: Under custom_jsps folder we must have to create same directory structure as Liferay source code after docroot directory.

    Step 4: Open the login.jsp file and add below line. 

    Your IP:<%=com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()%>
    

    And deploy the hook. Refresh the page to see the changes. That's all.

     

    Download Source Code

    Post Tagged with , ,

12 Responses so far.

  1. Parth Prajapati says:

    hi Hamidul!
    your post are really helpful.
    I want to create a form which contains multiple jsp page.
    for that I have used .
    now i want to customize it for "Next" button which will bring me to next respective jsp page.
    thank you.

  2. Rithika Sri says:

    Thanks for the post.

    I did as you said. But it override all the the content in sign in portlet and displays only Your IP:127.0.0.1

    What is the problem here?

  3. Rithika Sri says:

    How to import the zip file into eclise?

    That zip file is created by you? or liferay’s sign-in portlet?

    so many doubts are there.. Please explain me

    Regards,

    Rithika

  4. MastanRao says:

    Hello Hamidul Islam,

    I downloaded the source code zip file and trying to modify the content in login.jsp, but it showing lot of errors actually there is no import statements in that jsp, I am beginner in liferay i don't know which statements i have to import could you provide me the updated one.

    I have a some requirement could you please help on this:
    After login to the application i have to redirect to particular page how can i do this could you please guide me on this or give some pointers to proceed.

    Thank you so much! your post is helped me lot for creating the hook.

    Regards
    MastanRao.

  5. MastanRao says:

    Hello Hamidul Islam,

    Thank you so much for your quick response!

    Could you please help on the below thing:
    After login need to redirect to particular page where can i do it or give me some pointers or urls which will help on these.

    Thanks
    MastanRao.

  6. Anjaneya says:

    Am overriding login.jsp . Please let me know how can i add js files ex jquery.min.js or bootstrap js file to it.

  7. Anju says:

    HI ,

    I would like to know how to add a new entity in the social activity page in liferay using Hook .

    Thanks

  8. kiran says:

    hi,
    how to saperate "create_account and forget_password" url links in navigation.jsp using liferay login hook.

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Top
%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close