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
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