Liferay 7 overriding MVC Commands

  • MVCActionCommand: An interface that allows the portlet to process a particular action request. By extending BaseMVCActionCommand, we can customize processAction method.
  • MVCRenderCommand: An interface that handles the render phase of the portlet. By  extending BaseMVCRenderCommand, we can customize render method.
  • MVCResourceCommand: An interface that allows the portlet to serve a resource. By extending BaseMVCResourceCommand, we can customize serveResource method.
Now , we will see how to customize processAction method.

Step 1:


Initially, Create one module as mentioned in Liferay 7 document.

Step 2:


In controller class, write the component property depends on which modules you are customizing,

for eg., if we customize create account page, write as following

@Component(
property = {
"javax.portlet.name=com_liferay_login_web_portlet_FastLoginPortlet",
"javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet" ,
"mvc.command.name=/login/create_account",
"service.ranking:Integer=100" 
},
service = MVCActionCommand.class
)

Note : service = MVCActionCommand.class is based on which interface we are overriding.

Step 3:


For MVC action command overrides, extend BaseMVCActionCommand, and the only method you’ll need to override is doProcessAction, which must return void.

for eg.,

public class samplePortlet extends BaseMVCActionCommand  {

@Override

protected void doProcessAction(

ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {

  mvcActionCommand.processAction(actionRequest, actionResponse); // it process existing logic

System.out.println("inside process action");
}

@Reference(
       target = "(&(mvc.command.name=/login/create_account)(javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet))"
       )
public void setMvcActionCommand(MVCActionCommand mvcActionCommand) {
     this.mvcActionCommand = mvcActionCommand;
   }
protected MVCActionCommand mvcActionCommand;
}

For more details, Refer here.

Comments

  1. Replies
    1. Hi,

      I am trying to overrride EditDiscussionStrutsAction class in liferay-dxp. It is a StrutsAction class . which has following property:

      @OSGiBeanProperties(
      property = "path=/portal/comment/edit_discussion",
      service = StrutsAction.class
      )

      would you please tell me how to override it..!

      Thanks

      Delete
  2. Very good article, but I have a question.
    Can I Override the addUser method?

    ReplyDelete
  3. very good post.how to override documents and media actions.

    ReplyDelete
  4. In LIferay 7 , How to Create a Custom Struts Action ?. I got the reference of overriding struts action . In LIferay 6.2 , custom struts action achieved by using lIferayhook.xml But In LIferay 7 , I did not get the Idea. Please Help me out in this problem .

    ReplyDelete
    Replies
    1. Hey Aravind, have you got how to override StrutsAction . please help me. i am also faccing same problem.!!

      Delete

Post a Comment

Popular posts from this blog

Display portlet as popup in theme

Liferay migration to version 7.x