• Spring Portlet In Liferay 7 DXP

    Spring Portlet In Liferay 7 DXP

    Creating Spring Portlet was a nightmare In Liferay 7 DXP, in the Latest version of the Liferay IDE it has been made so simple to create a Spring Portlet Using Liferay IDE

    Environment
    Liferay IDE 3.1.1 GA2
    Liferay CE Portal Tomcat 7 GA4
    JDK 8
    MySql 5.7

    Step 1: Create A Module Project

    Select "spring-mvc-portlet" project Template.


    Click Next

    Step 2 : Portlet Class Name and  Package Name



    Click Finish, Then You can see the project directory structure as shown below.


    Congrats, You have just created a Spring Portlet in Liferay 7.

    Portlet Controller Class

    Annotations in Spring MVC Portlet


    • @Controller

    When we use this annotation in the class The Spring Bean Container Considers the Class as a Portlet Controller which handles all the portlet requests comes to the portlet

    • @RequestMapping

    As we know there are different modes of portlet such as VIEW, EDIT and HELP, We can configure the portlet to handle the request only for a specific mode, in our case we are going to use the Portlet Controller only for handling requests in VIEW mode,  so it will be @RequestMapping("VIEW")

    • @ActionMapping

    In Liferay Portlet MVC we have processAction() method to handle the Action Requests comes to the portlet, similarly we can define Action Methods for Action URLs using this  Annotation

    • @RenderMapping

    We can use the @RenderMapping annotation to handle the Render Requests for Render URLs, We can Return the Page Name in the Render Methods, the returned page will be rendered in the portlet.

    • @ResourceMapping

    In Liferay Portlet MVC we have  serveResource() method to handle the Resource Requests, similarly  we can define Resource Methods for Resource URLs using this annotation with an id


    Web.xml

    web.xml is the root file for spring portlet, Spring Portlet Configurations starts from this file.

    portlet-application-context.xml

    View Resolver Configurations can be made in this file

    • contentType : view character encoding
    • prefix : view Files Path
    • suffix : view (File)Type
    • viewClass : View Resolver class for Markup language


  • 2 comments:

    1. The project structure looks like spring plugin project. But when we create spring mvc module all the XMLS should be configured in annotation.

      ReplyDelete
    2. Thank you for taking the time to discuss this. I strongly believe in it and I'm looking forward to learning more about it. If possible, should you gain more expertise, would you be willing to update your blog with additional information? Spacebar clicker provides you with a computer counter to determine your spacebar clicks per second. spacebar click test .All you need to do is keep clicking for a specified period.

      ReplyDelete