Liferay 7 MVCActionCommand Example

Liferay 7 MVCActionCommand Example helps developers in understanding creation of mvc action commands in liferay.  Let’s create for a sample action command class for editLeave in leave application.

Please go through the below tutorial for understanding Liferay 7 MVC Commands:

Liferay 7 Portlet Commands Example

Liferay 7 Portlet Commands Example tutorial helps developers in creating commands rather writing up all action,resource methods in Portlet controller.READ MORE

Let’s jump into the tutorial:

  1. Add in LeavePortlet Controller  if not there
    1. @Component(
       immediate = true,
       property = {
       "javax.portlet.display-name=Leave Application",
       service = Portlet.class
      public class LeavePortlet extends MVCPortlet {
  2. Create EditLeaveActionCommand  class and make that as OSGI Component with below config:
    1. @Component(
       property = {
       service = MVCActionCommand.class
      public class EditLeaveActionCommand extends BaseMVCActionCommand {
       private LeaveLocalService leaveService;
       @Reference(unbind = "-")
       protected void setLeaveService(LeaveLocalService leaveService) {
       this.leaveService = leaveService;
       protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) 
       throws Exception {
       SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
       String name = ParamUtil.getString(actionRequest, "name");
       System.out.println("Leave Edit"+name);
       Date startDate= ParamUtil.getDate(actionRequest, "startDate",sdf );
       Date endDate = ParamUtil.getDate(actionRequest, "endDate", sdf);
       ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
       long groupId = themeDisplay.getScopeGroupId();
       Leave leave = leaveService.addLeave(name, themeDisplay.getRealUserId(), groupId,
       themeDisplay.getCompanyId(), startDate, endDate);
  3.  In JSP,  portlet action URL should be like belows. We can use either of below action requests:
    1. <liferay-portlet:actionURL name="leave_editLeave" var="editLeave">
           <portlet:param name="mvcActionCommand" value="leave_editLeave" /> 
    2. <liferay-portlet:actionURL name="leave_editLeave" var="editLeave">
      <aui:form action="<%= editLeave %>" cssClass="container-fluid-1280" method="post" name="fm"> 

Access other MVC Command Examples:

Liferay 7 MVC Render Command Example

Liferay 7 MVC Render Command Example will helps in understanding mvc render command along with code snippet. Let jump into the creation of MVC render command. Liferay 6 versions uses below approaches to redirect…


Liferay 7 MVC Resource Command Example

Liferay 7 MVC Resource Command Example tutorial helps in understanding Liferay 7 resource command. Let’s look into creation of sample resource command class for deleteLeave in leave application. Please go through the below tutorial for…

Leave a Reply

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