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

 

MVC Resource Command Tutorial:

  • Add javax.portlet.name in LeavePortlet Controller  if not there
    1. @Component(
       immediate = true,
       property = {
       "com.liferay.portlet.display-category=category.sample",
       "com.liferay.portlet.instanceable=true",
       "javax.portlet.display-name=Leave Application",
       "javax.portlet.name=org_javasavvy_web_leave_portlet",
       "javax.portlet.init-param.template-path=/",
       "javax.portlet.init-param.view-action=/leave/view",
       "javax.portlet.init-param.view-template=/leave/view.jsp",
       "javax.portlet.resource-bundle=content.Language",
       "javax.portlet.security-role-ref=power-user,user"
       },
       service = Portlet.class
      )
      public class LeavePortlet extends MVCPortlet {
       
      }
  • Create DeleteLeaveResourceCmd   class and update the class with below config:
    1. @Component(
       property = {
       "javax.portlet.name=org_javasavvy_web_leave_portlet",
       "mvc.command.name=delete_leave_res"
       },
       service = MVCResourceCommand.class
       )
      public class DeleteLeaveResourceCmd extends BaseMVCResourceCommand {
      
       private LeaveLocalService leaveService;
       
       @Reference(unbind = "-")
       protected void setLeaveService(LeaveLocalService leaveService) {
      
       this.leaveService = leaveService;
       }
       
       @Override
       protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
       throws Exception {
       
       System.out.println("in delete leave Resource cmd ");
       
       }
      
      }
  •  In JSP,  portlet resource URL will be:
    1. <portlet:resourceURL id="delete_leave_res" var="deleteLeaveRes">
       <portlet:param name="leaveId" value="<%=String.valueOf(leaveId) %>"/>
      </portlet:resourceURL>
    2. <aui:a href="<%=deleteLeaveRes %>">Click here to delete</aui:a>

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…

READ MORE

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…
READ MORE

Leave a Comment

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