01 January, 2013

Liferay MVC Portlet

During the render phase of the portlet lifecycle, the Liferay MVC Portlet also looks for a specific render parameter named jspPage.

The jspPage value should be a valid jsp page, including the path. ex. jspPage = “/html/showEditPublisher.jsp”
If jspPage is defined within the renderRequest, then the portlet will dispatch to the jspPage directly.

This means that if you're creating portlet whose sole purpose is to display data, you don't necessarily need to ever create a portlet class, the included com.liferay.util.bridges.mvc.MVCPortlet class provides all the portlet functionality you need and you're free to spend your time developing the view layer of your application.



Let's see how to control page flow with the Liferay MVC Portlet.
  • Open the docroot/view.jsp file
  • Add the following (01-view.jsp) to the bottom of the file.
                <portlet:renderURL var="editUser">
                <portlet:param name="jspPage" value="/edit_user.jsp" />
                 </portlet:renderURL>
                <p><a href="<%= editUser %>" >Click here to edit user record</a></p>
  • Create a new file in the docroot directory named edit_user.jsp and write any sample code.
  • Click on the new link you created to see the edit user form displayed.

  • If your portlet requires the action phase of the portlet lifecycle (and most portlets do), the Liferay MVC Portlet provides two options.
  • Option 1, which is used for most use cases, requires you create own class that extends MVCPortlet and add your action methods to that class.
  • Option 2, which is used for very large and complex portlet applications allows you to break out your actions into their own classes. 
  • By following a standard naming convention, the MVCPortlet handles invoking the appropriate action without the use of complext xml based
configuration files.

As you see from this simple portlet, the Liferay MVC Portlet provides:
  • A simple Controller that can be easily extended for more complex applications
  • A View layer that leverages your existing knowledge of Java Server Pages
  • Complete freedom to implement your Model layer with any technology you choose, but as we'll see in our next example the framework works very nicely with a Model layer that's been generated with the Liferay Service Builder.
Note : However, the Liferay MVC Portlet might not be the right choice for every situation so it's important to evaluate your needs and the benefits provided by all of the application frameworks before making a choice.

Rate Me:

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...